1
奇怪的行爲我有一個WCF服務是這樣的:對WCF InstanceContextMode.Single + ConcurrencyMode.Single
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Single)]
public class MyWcfService
{
public void StartIt()
{
MyWorkManager mgr = new MyWorkManager(new MyWorker());
mgr.StartWorker();
}
}
MyWrokManger的StartWorker方法只是開始用start方法一個新的線程指出MyWorker的StartWork方法。這裏的MyWorker類:
public class MyWorker
{
public void StartWork()
{
Mylogger.Log("Starting work...");
// Call a long running method
LongRunningMethod();
Mylogger.Log("Completed work.");
}
private void WorkerMethod()
{
Mylogger.Log("Starting WorkerMethod()...");
// do something here
Mylogger.Log("Completed WorkerMethod().");
}
}
然後我用我的客戶來調用服務兩次在一個循環中,在這裏就是我在日誌中看到(按時間戳排序):
Invocation ThreadID Message
=================================================
1 5 Starting work...
2 7 Starting work...
2 7 Starting WorkerMethod()...
1 5 Starting WorkerMethod()...
2 7 Completed WorkerMethod().
1 5 Completed WorkerMethod().
2 7 Completed work.
1 5 Completed work.
哪有第二在第一次之前完成調用?我認爲每個方法調用都是順序的。我錯過了什麼?
是的,我認爲這是問題所在。 WCF InstanceContext和Concurrency模式只控制服務線程,但我的工作管理器產生了我需要管理自己的工作線程。 – notlkk 2011-01-21 00:42:18