private void SyncNetData() { bool needHoldSMClient = false; int count = 0; while (true) { needHoldSMClient = false; try { semaphoreFull.WaitOne(); HttpResponseMessage response = new HttpResponseMessage(GetNetWorkStream()); string rawData = response.GetContent(); Invoke(new UpdateUI(delegate() { richTextBox1.Text = richTextBox1.Text + "\r\n" + rawData; })); SetFlag(false); try { Execute excuteResponse = SoapDecoder.Deserialize <Execute>(rawData); if (excuteResponse.ClientRequestEntity != null && excuteResponse.ClientRequestEntity.Name == "debug") { foreach (MessageItem item in excuteResponse.ClientRequestEntity.Messages.Messages) { if (item.Text.StartsWith("Breakpoint reached for")) { needHoldSMClient = true; break; } } if (debugEntity != null) { Invoke(new UpdateUI(delegate() { debugEntity.AddTrace(excuteResponse); })); } } } catch (Exception ex) { //Nothing to do. } if (needHoldSMClient) { //break; Thread.CurrentThread.Suspend(); } count = 0; } catch (Exception ex) { SetFlag(true); count++; if (count >= 2) { // } } finally { try { semaphoreEmpty.Release(); } catch { //nothing to do } } } }
/// <summary> /// Sync data to SM client. /// /// </summary> private void SyncNetData() { int count = 0; while (true) { //In the beginning, not hold the sm client. //needHoldSMClient = false; try { //Wait until semaphorefull is signaled. //Means new data is avaible in shared memory. semaphoreFull.WaitOne(); //Build the http message. HttpResponseMessage response = new HttpResponseMessage(GetNetWorkStream()); //Get the raw content of http message. string rawData = response.GetContent(); //Just for testing. show the data to UI. Invoke(new UpdateUI(delegate() { //richTextBox1.Text = richTextBox1.Text + "\r\n" + rawData; })); SetFlag(false); try { //Deserialize the http message to Execute object. Execute excuteResponse = SoapDecoder.Deserialize <Execute>(rawData); if (excuteResponse.ClientRequestEntity != null && excuteResponse.ClientRequestEntity.Name == "debug") { if (!clientEverHeld) { foreach (MessageItem item in excuteResponse.ClientRequestEntity.Messages.Messages) { if (item.Text.StartsWith("Breakpoint reached for")) { //When encounter the debug start message then hold sm client. needHoldSMClient = true; break; } } } else { needHoldSMClient = true; } //Add trace response to debug entity. if (debugEntity != null) { Invoke(new UpdateUI(delegate() { debugEntity.AddTrace(excuteResponse); })); autoStepThread = new Thread(new ThreadStart(AutoGotoNextStep)); autoStepThread.Start(); } } else { needHoldSMClient = false; } } catch (Exception ex) { needHoldSMClient = false; //Nothing to do. } clientEverHeld = (clientEverHeld || needHoldSMClient); if (needHoldSMClient) { //break; Thread.CurrentThread.Suspend(); } count = 0; } catch (Exception ex) { SetFlag(true); count++; if (count >= 2) { // } } finally { try { //Release semaphoreempty, so that debugger core can put data to shared memory. semaphoreEmpty.Release(); } catch { //nothing to do } } } }