大家好~
我最近在wince上寫了一個C#的程式
是用RS232接收資訊~修改UI介面上的label文字
但很糟糕的是我用PC上執行的時候文字顯示都沒問題
到wince上執行時就會出現
NotSupportedException
Microsoft.AGL.Common.Misc.HandleAr();
System.Windows.Forms.COntrol.get_Text();
System.Windows.Forms.COntrol.set_Text();
...
的錯誤訊息
我一直以為是我那裡寫的不太好~還是wince4.2版沒支援
所以我做了一些測試和看了一堆文章
測試在UI上加一個button ,按下button後UI上的Label文字會變更,
這個測試沒問題~button按下後label的文字確實改了,理論上也就是wince4.2版應該有支援
看了一堆文章...不過都是寫VS2005的,要用委派和多緒來寫
所以我也改了委派和多緒來寫,但...還是一樣的錯誤...
所以~只好來這裡求高手幫提點指教T T~幫個忙~
我學C#是最近半年的事~我之前都是寫JAVA的^^
感恩~
我寫的程式碼最後大約如下:
public partial class Form1 : Form
{
private Form1()
{
InitializeComponent();
}
private static Form1 instance;
public static Form1 getinstance() {
if (instance == null)
instance = new Form1();
return instance;
}
private void button1_Click(object sender, EventArgs e)
{
Console.Write("test");
this.Test_label.Text="Test";
}
public void changeText(string message)
{
this.Test_label.Text = message;
}
}
================================================
收到Rs232資訊後,會觸發CVDemoOperation(int infoType,string Info,string Publisher)
CVDemoOperation(int infoType,string Info,string Publisher)程式碼如下
================================================
public delegate void Del(string message);
string final = "";
public CVDemoOperation(int infoType,string Info)
{
try
{
form1 = Form1.getinstance();
}
catch (Exception e)
{
Console.WriteLine("Error " + e);
}
Console.WriteLine("Info = " + Info);
final = Info;
StartThread();
}
void StartThread()
{
System.Threading.Thread t1 = new System.Threading.Thread
(delegate()
{
form1 = Form1.getinstance();
Del a = form1.changeText;
a(final);
});
t1.Start();
}