I'm having some trouble with threading on a Motorola Q Smartphone which runs WM5 as you know.
I have a C# program that I've been running under XP quite successfully. When I recompile it (with a different UI of course) for the Q, the threads to not start. Here's a code snippet...
_thread = new Thread(new ThreadStart(Receiver));
_thread.Start();
which is executed in the main thread and where Receiver is:
private void Receiver()
{
...
}
I have some debug output that dumps messages to a text box on the display. The message dumped by the thread when it first starts never makes it to the display. Any ideas why this simple code would work under XP but not on a Q
Thanks,
FM

Trouble with Threading on Motorola Q Smartphone
SilverWing
Probably because you're not using Control.Invoke to access UI (e.g. Textox) from another thread. On NETCF V1 it would lead to a hang in most cases, NETCF V2 would throw an exception. On XP is would work most of the time and hang rarely.
Eldoktor
I would guess you've declared _form as ‘Form’ and ‘Form’ does not have DelegateInstanceLogMessage. Class ‘main’ does. Either declare _form as ‘main’ or cast to it.
DanBrink
namespace MyNamespace
{
// I assume this is my delegate template
public delegate void DelegateLogMessage(string msg);
public partial class main : Form
{
// ... and this would be the instance of my delegate ...
public DelegateLogMessage DelegateInstanceLogMessage;
private void LogMessage(string msg)
{
// _log is of class Log which encapsulates access to the TextBox
_log.Message(msg);
}
public main()
{
DelegateInstanceLogMessage = new DelegateLogMessage(this.LogMessage);
// Here we're passing a the main Form and the Log class to another class that will spin off the thread
_myClass = new MyClass(this, _log);
}
}
}
namespace MyNamespace
{
public partial class MyClass
{
public MyClass(Form form, Log log)
{
_form = form;
_log = log;
// ... here we spin off the Thread that also wants to log messages
_thread = new Thread(new ThreadStart(Receiver));
_thread.Start();
}
}
}
namespace MyNamespace
{
public partial class MyClass
{
private void ReceiverLogMessage(string msg)
{
_form.Invoke(_form.DelegateInstanceLogMessage, new Object[] { msg });
}
private void Receiver()
{
ReceiverLogMessage("Some log output...");
}
}
}
What I'm getting back when I try to build this using VS2005 is the following error:
Error 1 'System.Windows.Forms.Form' does not contain a definition for 'DelegateInstanceLogMessage' E:\Visual Studio 2005 Projects\Cornfed SIP Mobile\Cornfed SIP Mobile\SIP User Agent Receiver.cs 11 36 Cornfed SIP Mobile
This error occurs at the _form.Invoke line...
I've declared DelegateInstanceLogMessage in the main class as public and passed the Form to the class thats using it. Why am I getting this error
Thanks,
FM
Dexter Peabody
MSDN has sample on that (and pretty much everything else). You can also search NETCF news group and this forum – that issue is quite common.
newbieneedshelp
Thanks for the reply. This might explain why I could not reference CheckForIllegalCrossThreadCalls under CF2. This was necessary to make the threading work under XP.
I'm not familiar with Control.Invoke. Can you provide some example code of how you would access a textbox from the main thread and from the created thread Or could you point me at a good tutorial page on it
Thanks,
FM