All Forums
 Microsoft Windows CE
 .NET Application Development
 Thread stop with GCX
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Author Topic  

opsens_claude_belleville

34 Posts

Posted - 29 Aug 2005 :  16:20:26  Show Profile

I'm trying to do simple thread and stop functionnalities.

I start / stop serveral time the thread,
sometimes the thead doesn't consider the global variable that
tells the thread to stop

Don't know if it helps but my Thread fire an event handle into the same class.


Don't know how to include my project to this topic so I will copy-paste the essential of the problem

========================================================
#region Member variables and Event
public System.Threading.Thread mThreadAcquire;
public bool mAcqThreadIsRunning = false;
public System.Threading.Mutex mAcqThreadRunning;

public delegate void OnData(long aData);
public event OnData OnDataExecute;
#endregion

private void cmdStart_Click(object sender, System.EventArgs e)
{

cmdStart.Enabled = false;
cmdStop.Enabled = true;
OnDataExecute += new OnData(Main_OnData);

//Start the thread
mThreadAcquire = new Thread(new ThreadStart( thread_Data));
mAcqThreadRunning = new Mutex();

mAcqThreadIsRunning = true;
mThreadAcquire.Start();

}

private void Main_OnData(long aData)
{
lblData.Text = aData.ToString();
}

private void cmdStop_Click(object sender, System.EventArgs e)
{
mAcqThreadIsRunning = false;

//Wait for thread to stop
mAcqThreadRunning.WaitOne();
mAcqThreadRunning.ReleaseMutex();
mAcqThreadRunning.Close();

cmdStart.Enabled = true;
cmdStop.Enabled = false;

OnDataExecute -= new OnData(Main_OnData);
}


private void thread_Data()
{
long lCount = 0;

mAcqThreadRunning.WaitOne();

try
{
//Read member variable
while (mAcqThreadIsRunning)
{
lCount+=1;

OnDataExecute(lCount);

System.Threading.Thread.Sleep(200);
}
}
catch {}

mAcqThreadRunning.ReleaseMutex();
}

========================================================

Thanks

Phil
  Topic  
 Forum Locked
 Send Topic to a Friend
 Printer Friendly
Jump To:
Eurotech Support Forums © Eurotech Inc. Go To Top Of Page
This page was generated in 0.02 seconds. Snitz Forums 2000