问题描述
您好,专家,
在我的C#Windows应用程序中,
我有两个按钮可以导出和取消.
在我的导出按钮中,这里我将sql数据表导出到在线程下运行的.csv file.its.
Hi Experts,
In my c# windows application,
I have two buttons export and cancel.
In my export button, here i am exporting sql datatable to .csv file.its running under the thread.
thrThreadExportProcess = new Thread(new ThreadStart(startExport));
thrThreadExportProcess.Start();
thrThreadExportProcess.IsBackground = true;
在其导出过程运行时,用户在此处单击取消"按钮,我正在中止线程,然后加入线程并删除导出的文件.
在加入Thread的同时,应用程序get挂起了一段时间,然后它将运行.
我的问题是为什么它挂了一段时间.
这是取消"按钮中代码的一部分.
while its exporting process is running, user hits the cancel button here i am aborting the thread,then joining the thread and deleting the exported file.
while its joining Thread, application get hangs up some time then it will run.
my question is why its hangs up some time.
here is the part of the code in cancel button.
if (thrThreadExportProcess.IsAlive)
{
thrThreadExportProcess.Abort();
thrThreadExportProcess.Join();
File.Delete(csvPath);
}
请提供您的宝贵建议.
Kindly provide your valuble Suggestions.
推荐答案
这篇关于C#Windows应用程序中的Thread.abort()和Thread.join()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!