【发布时间】:2023-03-22 17:26:01
【问题描述】:
这是我正在尝试运行的应用程序的图片:
当我尝试在外部单击、移动或最小化它时,窗口会挂起:
我的代码:
public void Process()
{
// using (HalconDotNet.HWindowControl HWinCtrl = new HalconDotNet.HWindowControl())
// {
using (PitFinderEngine VisionEngine = new PitFinderEngine())
{
foreach (string jpegfile in JpegFiles)
{
try
{
string[] parts1 = jpegfile.Split('\\');
string[] parts2 = parts1[parts1.Length - 1].Split('.')[0].Split('_');
string row = parts2[parts2.Length - 2].Split('R')[1];
string col = parts2[parts2.Length - 1].Split('C')[1];
Results.Add(row + " " + col, VisionEngine.action(jpegfile, "Production"));
//FormControls.ProgressBar_DoStep();
}
catch (Exception e)
{
}
}
}
}
“进程”以这种方式调用:
public static Thread StartTheThread(string LN, string TN)
{
var t = new Thread(() => RealStart(LN, TN));
t.Start();
return t;
}
private static void RealStart(string ln, string tn) {
Lots[ln].Tiles[tn].Process();
}
public static void DoWork()
{
string[] Directories = Directory.GetDirectories(LotPictureFolder);
List<Thread> ThreadList = new List<Thread>();
foreach (string lot in Directories)
{
string[] parts = lot.Split('\\');
string LotName = parts[parts.Length - 1];
foreach (string tile in Lots[LotName].Tiles.Keys)
{
if (!Lots[LotName].Tiles[tile].VicFileFound)
{
ThreadList.Add(StartTheThread(LotName, tile));
}
}
}
bool AllDone = false;
while (!AllDone)
{
AllDone = true;
foreach (Thread th in ThreadList)
{
if (th.IsAlive)
{
AllDone = false;
}
}
}
}
好像
VisionEngine.action(jpegfile, "Production")
运行需要 10ms - 20ms 并负责挂起窗口,如果我要移动窗口;意思是,如果我要评论它,问题就不会存在,是否可以隔离此代码,我尝试使用线程,但问题仍然存在,我无法使用任务,因为平台是 .Net3.5。
【问题讨论】:
标签: c# .net windows multithreading