❔ Threading-unsure im doing this correctly, Ui thread gets frozen.

var thread = new Thread(new ThreadStart(DelaySpashClose));

while (IsFileLocked())
{
if (!thread.IsAlive)
{
thread.Start();

}
}
var thread = new Thread(new ThreadStart(DelaySpashClose));

while (IsFileLocked())
{
if (!thread.IsAlive)
{
thread.Start();

}
}
private void DelaySpashClose()
{
Thread.Sleep(1000);
}
private void DelaySpashClose()
{
Thread.Sleep(1000);
}
Any Ideas?
7 Replies
Trinitek
Trinitek3y ago
if you set a breakpoint the debugger will reveal this, but I suspect your while loop is spinning indefinitely waiting for the file to unlock that is of course happening on the UI thread
antimatter8189
antimatter8189OP3y ago
Yeah the reason i figure, idk how to get around that Because if the ui gets stuck i cant close the open file
Trinitek
Trinitek3y ago
you should prefer using async and Task versus creating your own threads how is this code being called? is it in an event? $async
MODiX
MODiX3y ago
For an introduction to async and await in C#, https://blog.stephencleary.com/2012/02/async-and-await.html
Async and Await
Most people have already heard about the new “async” and “await” functionality coming in Visual Studio 11. This is Yet Another Introductory Post.
Trinitek
Trinitek3y ago
there's a snippet in there that shows how it ties in with events, like button presses
antimatter8189
antimatter8189OP3y ago
Ik about async and await im working on a complex project which has ALOT of sub projects dependencies etc events wrappers delegats threads are all over the code there are alot of threads runing at the same time so i cant just break code convention and go my own way
Accord
Accord3y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?