T
Tyler Sample
I've been having strange thread conflicts, and after moving the relevant
mutex higher and higher I've finally determined that the mutex doesn't
seem to be working at all.
Here is the relevant code:
private static Mutex previewMutex = new Mutex();
private static void preview (string source, string target)
{
try
{
previewMutex.WaitOne();
if (previewerThread != null && previewerThread.IsAlive)
{
evl.WriteEntry("WaitingForPreviewerThread");
previewerThread.Join();
evl.WriteEntry("FinishedWaiting");
}
DocSearch.previewSource = source;
DocSearch.previewTarget = target;
previewerThread = new Thread (DocSearch.previewStarter);
previewerThread.Priority = ThreadPriority.Normal;
previewerThread.Name = "PreviewDownloader";
previewerThread.Start();
previewMutex.ReleaseMutex();
}
catch(Exception err)
{
evl.WriteEntry(err.ToString());
}
}
What's happening is the mutex is not blocking properly. I look in the
event log and see the WaitingForPreviewerThread message three times in a
row, with no messages at all in between. I've verified that log message
isn't anywhere else in the code and this is the only place previewMutex
is used. The really messed up thing is that this function is only
called from a GUI event handler (OnChange event for a ListView). From
my understanding from doing MFC and Win32 programming, the GUI should
only have one active thread by default anyway, meaning this shouldn't be
possible regardless of the mutex. The code works as expected if the
user slowly arrows through the listbox including all the expected event
log messages.
Here's what the thread does, if it matters:
public static void backgroundPreview()
{
try
{
Common.GetFile(DocSearch.previewSource,DocSearch.previewTarget);
Common.SendMessage (Common.mainHwnd, Common.WM_PREVIEWREADY, 0, 0);
}
catch (Exception err)
{
evl.WriteEntry(err.ToString());
}
}
GetFile calls a web service and downloads a file. SendMessage is the
win32 API.
The handler for WM_PREVIEW is in the same form class that activates the
thread, and it displays a picture in an activeX control.
Any help is greatly appreciated!
Tyler
mutex higher and higher I've finally determined that the mutex doesn't
seem to be working at all.
Here is the relevant code:
private static Mutex previewMutex = new Mutex();
private static void preview (string source, string target)
{
try
{
previewMutex.WaitOne();
if (previewerThread != null && previewerThread.IsAlive)
{
evl.WriteEntry("WaitingForPreviewerThread");
previewerThread.Join();
evl.WriteEntry("FinishedWaiting");
}
DocSearch.previewSource = source;
DocSearch.previewTarget = target;
previewerThread = new Thread (DocSearch.previewStarter);
previewerThread.Priority = ThreadPriority.Normal;
previewerThread.Name = "PreviewDownloader";
previewerThread.Start();
previewMutex.ReleaseMutex();
}
catch(Exception err)
{
evl.WriteEntry(err.ToString());
}
}
What's happening is the mutex is not blocking properly. I look in the
event log and see the WaitingForPreviewerThread message three times in a
row, with no messages at all in between. I've verified that log message
isn't anywhere else in the code and this is the only place previewMutex
is used. The really messed up thing is that this function is only
called from a GUI event handler (OnChange event for a ListView). From
my understanding from doing MFC and Win32 programming, the GUI should
only have one active thread by default anyway, meaning this shouldn't be
possible regardless of the mutex. The code works as expected if the
user slowly arrows through the listbox including all the expected event
log messages.
Here's what the thread does, if it matters:
public static void backgroundPreview()
{
try
{
Common.GetFile(DocSearch.previewSource,DocSearch.previewTarget);
Common.SendMessage (Common.mainHwnd, Common.WM_PREVIEWREADY, 0, 0);
}
catch (Exception err)
{
evl.WriteEntry(err.ToString());
}
}
GetFile calls a web service and downloads a file. SendMessage is the
win32 API.
The handler for WM_PREVIEW is in the same form class that activates the
thread, and it displays a picture in an activeX control.
Any help is greatly appreciated!
Tyler