Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Debugger / ThreadWorkerController.cs / 1305376 / ThreadWorkerController.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Debugger { using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.SymbolStore; using System.Reflection; using System.Reflection.Emit; using System.Runtime; using System.Threading; // Define an auxiliary thread codegen technique for islands. // This executes the islands on a dedicated worker thread. The worker thread's // physical callstack then maps to the interpreter's virtual callstack. // It has an excellent Step-in/Step-over/Step-Out experience. [DebuggerNonUserCode] public class ThreadWorkerController { StateManager stateManager; // Set to true to notify to Break on first instruction. This helps the F11 on startup experience. // Since the islands are on a new thread, there may be no user code on the main thread and so // F11 doesn't work. Thus the new worker thread needs to fire some break event. // This gets reset after the 'startup breakpoint'. // The initial Properties can override this. bool breakOnStartup; // Own the worker thread. Thread worker; // Signalled when the main thread wants to send an event to the worker thread. // The main thread fills out the data first. AutoResetEvent eventSend; // Signalled by the worker thread when it's finished handling the event and // the main thread can resume. AutoResetEvent eventDone; EventCode eventCode; // Parameter for enter message. VirtualStackFrame enterStackParameter; internal void Initialize(string threadName, StateManager manager) { this.stateManager = manager; this.breakOnStartup = this.stateManager.ManagerProperties.BreakOnStartup; CreateWorkerThread(threadName); } internal void Exit() { // Implement with an unbalanced Leave. // This will get the Worker to return and the ThreadProc to exit. this.LeaveState(); this.worker.Join(); } [DebuggerHidden] void WorkerThreadProc() { Worker(false); this.eventDone.Set(); } // Private Entry point called from islands. Must be public so that the islands can invoke it. [Fx.Tag.InheritThrows(From = "Worker")] [DebuggerHidden] public static void IslandWorker(ThreadWorkerController controller) { if (controller == null) { throw FxTrace.Exception.ArgumentNull("controller"); } controller.Worker(true); } [DebuggerHidden] internal void Worker(bool isAtStartup) { if (isAtStartup) { // Fire the 1-time "startup" breakpoint. if (this.breakOnStartup) { if (Debugger.IsAttached) { Debugger.Break(); } this.breakOnStartup = false; } this.eventDone.Set(); } // The final terminator is when leave returns, but from a recursive call. bool leave = false; while (!leave) { this.eventSend.WaitOne(); switch (eventCode) { case EventCode.Enter: // Call Island for enterStackParameter this.stateManager.InvokeWorker(this, enterStackParameter); // resume from SendLeave() this.eventDone.Set(); break; case EventCode.Leave: leave = true; return; case EventCode.Break: Debugger.Break(); this.eventDone.Set(); break; } } } void CreateWorkerThread(string threadName) { this.eventSend = new AutoResetEvent(false); this.eventDone = new AutoResetEvent(false); this.worker = new Thread(new ThreadStart(WorkerThreadProc)); string name = string.IsNullOrEmpty(threadName) ? this.stateManager.ManagerProperties.AuxiliaryThreadName : threadName; if (name != null) { this.worker.Name = name; } this.worker.Start(); } internal void EnterState(VirtualStackFrame newFrame) { this.eventCode = EventCode.Enter; this.enterStackParameter = newFrame; this.eventSend.Set(); // Block until Island executes Nop, // giving BPs a chance to be hit. // Must block here if the island is stopped at a breakpoint. this.eventDone.WaitOne(); } internal void LeaveState() { this.eventCode = EventCode.Leave; this.eventSend.Set(); // Block until call has exited. this.eventDone.WaitOne(); } internal void Break() { this.eventCode = EventCode.Break; this.eventSend.Set(); this.eventDone.WaitOne(); } // Type of event being fired. enum EventCode { Enter, Leave, Break }; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WSSecurityOneDotZeroSendSecurityHeader.cs
- WebControlsSection.cs
- BufferedStream2.cs
- TextTreeUndoUnit.cs
- DoubleAnimationUsingKeyFrames.cs
- PathFigure.cs
- WebServicesSection.cs
- DataGrid.cs
- NextPreviousPagerField.cs
- HandlerBase.cs
- DesignerTransactionCloseEvent.cs
- InheritanceContextHelper.cs
- ArrayWithOffset.cs
- ProcessHostServerConfig.cs
- NativeStructs.cs
- ElementInit.cs
- DataGridViewCellPaintingEventArgs.cs
- UnmanagedMemoryStream.cs
- ListViewItem.cs
- SettingsAttributeDictionary.cs
- JavaScriptString.cs
- BitmapFrameEncode.cs
- SharedPersonalizationStateInfo.cs
- StrongName.cs
- PageResolution.cs
- Matrix.cs
- XmlSerializationWriter.cs
- RtfControls.cs
- PasswordTextContainer.cs
- HttpPostProtocolImporter.cs
- CodeTypeDeclaration.cs
- XmlBinaryWriterSession.cs
- TextControlDesigner.cs
- SqlDataSourceCache.cs
- BrowserCapabilitiesFactory35.cs
- StringValueConverter.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- FormViewInsertEventArgs.cs
- TextModifier.cs
- ListControl.cs
- PartialCachingControl.cs
- StreamedWorkflowDefinitionContext.cs
- Models.cs
- HandlerBase.cs
- Grammar.cs
- CheckBoxField.cs
- CookieParameter.cs
- DispatcherTimer.cs
- ObjectItemCachedAssemblyLoader.cs
- SingleSelectRootGridEntry.cs
- KeyEvent.cs
- DeriveBytes.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- localization.cs
- XmlChildEnumerator.cs
- TransactionScope.cs
- SafeEventHandle.cs
- TdsParserSafeHandles.cs
- MenuEventArgs.cs
- SafeNativeMethods.cs
- ColumnWidthChangingEvent.cs
- SchemaNamespaceManager.cs
- SchemaElementLookUpTable.cs
- DataColumnPropertyDescriptor.cs
- PersistenceContextEnlistment.cs
- RuntimeEnvironment.cs
- PagerStyle.cs
- SchemaInfo.cs
- DesignConnectionCollection.cs
- QilChoice.cs
- SecurityUtils.cs
- RequestTimeoutManager.cs
- ListViewEditEventArgs.cs
- WebHttpDispatchOperationSelector.cs
- StorageConditionPropertyMapping.cs
- DocumentSchemaValidator.cs
- ConfigXmlAttribute.cs
- ImageAutomationPeer.cs
- InputEventArgs.cs
- SafeCertificateContext.cs
- PointUtil.cs
- Sorting.cs
- ApplicationSecurityInfo.cs
- PageHandlerFactory.cs
- DataPagerFieldCommandEventArgs.cs
- PersonalizationState.cs
- Expression.cs
- ActivityDesigner.cs
- OperationGenerator.cs
- VisualBasicImportReference.cs
- XPathNodeInfoAtom.cs
- FileLoadException.cs
- WebResourceAttribute.cs
- VisualStyleTypesAndProperties.cs
- _ListenerResponseStream.cs
- UnsafeNativeMethodsPenimc.cs
- externdll.cs
- SizeChangedInfo.cs
- EventLogPermission.cs
- TextDecorationCollection.cs