I’m calling a thread from within a for loop that closes a document. The problem is, the loop continues and tries to open another document before the code in the thread finishes. How can I pause the loop and wait for the document close event. Thanks.
edit
here is my code…
public void OpenFile()
{
for (int i = 0; i < 3; i++)
{
if (i != 1)
{
try
{
uiApp.OpenAndActivateDocument(TargetPath(i));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
ThreadPool.QueueUserWorkItem(new WaitCallback(CloseDoc));
}
}
static void CloseDoc(object stateInfo)
{
try
{
SendKeys.SendWait("^{F4}");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
I tried adding ‘Thread.Sleep(3000)’ after CloseDoc, that didn’t work. It looks like ‘waitone methods in manual/auto reset event classes’ would be my best bet. @GAPS can you elaborate? Thank you!
Please elaborate your question…
for time being to answer your question I will suggest you to use
waitonemethods inmanual/auto reset event classes. you can notify your waiting thread that your document is closed and then you can proceed.AutoReset
ManualReset