multi-thread :Can't call UccContext.AddNamedProperty ?
-
Saturday, February 28, 2009 10:05 AM
Problem:Can't call UccContext.AddNamedProperty in sub-thread.
Environment: XP sp2,.NET 3.5,uccapi 2.0,C#
I wanna create a UccContext and add some property on it, so i wrote following code:
----------------------------- CODE BEGIN -----------------------------
UccContext m_ctx;
m_ctx = new UccContextClass();
m_ctx.AddNamedProperty("testkey","testvalue");
----------------------------- CODE END -----------------------------
the code works very well when they are in main thread(e.g. in Form1()).
But when i wrote the same code in another thread, it throw a access violation exception.
----------------------------- CODE BEGIN -----------------------------
public Form1()
{
...
m_EngineThread = new Thread(CommandEngine.StartThread);
m_EngineThread.Start();
...
}
public static void StartThread()
{
int iRet;
string sRet;
UccContext m_uc;
...
m_uc = new UccContextClass();
m_uc.AddNamedProperty("something","somevalue"); <---- throw exception
....
}
----------------------------- CODE END -----------------------------
the parameters of AddNamedProperty is not the exception reason.
I tried follow codes, it still throw exception:
m_uc = new UccContextClass();
iRet = m_uc.Count; <--- throw exception
why it's so strange? Anyone has some suggestions?
All Replies
-
Wednesday, February 15, 2012 6:54 AMHi, We are facing the same problem. If you have solution for this problem please let us know. Thanks Annie
- Edited by Annie09 Wednesday, February 15, 2012 8:57 AM
-
Monday, February 20, 2012 7:34 AM
Hi could you try to use this code
UpdateVariables(string message) { if (this.InvokeRequred) { this.EndInvoke(this.BeginInvoke(new MethodInvoker(delegate() { UpdateVariables(message); } ))); } else { m_uc = new UccContextClass(); iRef = m_uc.Count; } }Regards
Thanks, MOHAMED A. SAKR | Software Development Lead Engineer | EgyptNetwork
- Proposed As Answer by MohamedSakr Monday, February 20, 2012 7:35 AM
-
Sunday, February 26, 2012 10:35 PMI am facing the same problem and i'll try the last solution
-
Tuesday, February 28, 2012 8:10 PM
It's working fine
Thanks MohamedSakr

