C
cty0000
I have some question..
This is my first time to use thread..
Following code does not have error but two warring
The warring is
Warning 2 'System.Threading.Thread.Suspend()' is obsolete:
'Thread.Suspend has been deprecated. Please use other classes in
System.Threading, such as Monitor, Mutex, Event, and Semaphore, to
synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202'
The warring are happened thread Resume/Suspend..
I'm not sure what is problem becuase thread programing is first time
for me...
This class to update message (GuiMsg) after received new message from
other class.
1. First application start, thread is resume by threadJob because
there are no message on QUEUE
2. If new message arrived, addNewMsg push new message to QUEUE
3. Resume thread to procss message(update)
4. Loop threadJob until QUEUE empty (during update, QUEUE can add new
msg)
===========================
Somewhere define and allowcate thread like flowing 3 line
Thread guiUpdateThread;
guiUpdateThread = new Thread(new ThreadStart(threadJob));
guiUpdateThread.Start();
public void addNewMsg(GUIMsg msg)
{
Monitor.Enter(GuiMsgQueue);
GuiMsgQueue.Enqueue(msg);
Monitor.Exit(GuiMsgQueue);
if (guiUpdateThread.ThreadState ==
ThreadState.Suspended)
guiUpdateThread.Resume();
}
private void threadJob()
{
GUIMsg gMsg;
while (true)
{
if (GuiMsgQueue.Count > 0)
{
Monitor.Enter(GuiMsgQueue);
gMsg = GuiMsgQueue.Dequeue();
Monitor.Exit(GuiMsgQueue);
update(gMsg);
}
else
{
if (guiUpdateThread.ThreadState ==
ThreadState.Running)
guiUpdateThread.Suspend();
}
}
}
Please help me..
This is my first time to use thread..
Following code does not have error but two warring
The warring is
Warning 2 'System.Threading.Thread.Suspend()' is obsolete:
'Thread.Suspend has been deprecated. Please use other classes in
System.Threading, such as Monitor, Mutex, Event, and Semaphore, to
synchronize Threads or protect resources. http://go.microsoft.com/fwlink/?linkid=14202'
The warring are happened thread Resume/Suspend..
I'm not sure what is problem becuase thread programing is first time
for me...
This class to update message (GuiMsg) after received new message from
other class.
1. First application start, thread is resume by threadJob because
there are no message on QUEUE
2. If new message arrived, addNewMsg push new message to QUEUE
3. Resume thread to procss message(update)
4. Loop threadJob until QUEUE empty (during update, QUEUE can add new
msg)
===========================
Somewhere define and allowcate thread like flowing 3 line
Thread guiUpdateThread;
guiUpdateThread = new Thread(new ThreadStart(threadJob));
guiUpdateThread.Start();
public void addNewMsg(GUIMsg msg)
{
Monitor.Enter(GuiMsgQueue);
GuiMsgQueue.Enqueue(msg);
Monitor.Exit(GuiMsgQueue);
if (guiUpdateThread.ThreadState ==
ThreadState.Suspended)
guiUpdateThread.Resume();
}
private void threadJob()
{
GUIMsg gMsg;
while (true)
{
if (GuiMsgQueue.Count > 0)
{
Monitor.Enter(GuiMsgQueue);
gMsg = GuiMsgQueue.Dequeue();
Monitor.Exit(GuiMsgQueue);
update(gMsg);
}
else
{
if (guiUpdateThread.ThreadState ==
ThreadState.Running)
guiUpdateThread.Suspend();
}
}
}
Please help me..