多线程:无法调用UccContext.AddNamedProperty? [英] multi-thread :Can't call UccContext.AddNamedProperty ?

查看:65
本文介绍了多线程:无法调用UccContext.AddNamedProperty?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:无法在子线程中调用UccContext.AddNamedProperty。
环境:XP sp2,.NET 3.5,uccapi 2.0,C#

我想创建一个UccContext并添加一些它上面的属性,所以我写了下面的代码:

----------------------------- CODE BEGIN --- --------------------------
UccContext m_ctx;

m_ctx = new UccContextClass();
m_ctx。 AddNamedProperty("testkey","testvalue");
----------------------------- CODE END --- --------------------------

代码在主线程中运行得非常好(例如在Form1()中)但是当我在另一个线程中编写相同的代码时,它会抛出一个访问冲突异常。
------------------------- ---- CODE BEGIN -----------------------------
public Form1()
{
。 ..
m_EngineThread = new Thread(CommandEngine.StartThread);
m_EngineThread.Start();





public static void StartThread()
{
int iRet;
串SRET;点击UccContext m_uc;搜索结果...结果m_uc =新UccContextClass();点击m_uc.AddNamedProperty("什么"," someValue中"); < ----抛出异常

....
}
------------------------- ---- CODE END -----------------------------

AddNamedProperty的参数不是例外原因。我试过跟随代码,它仍然抛出异常:

m_uc = new UccContextClass();
iRet = m_uc.Count; < ---抛出异常


为什么它如此奇怪?有人有什么建议吗?

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?

推荐答案

我们面临同样的问题。如果您有解决此问题的方法,请告诉我们。谢谢Annie
Hi, We are facing the same problem. If you have solution for this problem please let us know. Thanks Annie


这篇关于多线程:无法调用UccContext.AddNamedProperty?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆