.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Raising an Event in another thread from a Thread

Posted By:      Posted Date: October 11, 2010    Points: 0   Category :.NET Framework


I have a Polling thread which runs an infinite loop . and I have another thread(business) which is invoked by the UI thread based on user actions.

I need to raise an event in the polling thread from the business thread so that at the begining of the business thread (which is created  by

the UI thread bcause of a user action - say Button click - ) the event is raised and the event needs to be raised inside the Polling thread which is executing some complex logic inside a loop  and need to stop all of its operation temperorly so that the business thread can continue its work and after it completes the polling thread can resume its work , I have done the synchronization using the lock state ment but since the logic inside the loop of the polling thread is complex and takes time to complete each iteration , I need to stop the polling threads exection at the exact moment the business thread starts its execution - two threads share some  common hardware devices .


Is there any way to do this in .Net




View Complete Post

More Related Resource Links

Is it possible for one thread to catch an event thrown by another thread?

I have a very simple class (shown below) that monitors the mouse position on a separate thread to see if it is hovering over the same spot for more than a second.  I have to do this because the Windows Forms control I am using is an interop COM component that does not have or implement the MouseHover event. Anyway, the class that instantiates asrMouseHover (lets call it WinFormMain) adds a handler for the asrMouseHover.MouseIsHovering event.  The problem is, when this event is raised and caught, the handler in WinFormMain is running on the same thread as asrMouseHover.  I need it to run on WinFormMain... hence, is it possible for one thread to catch an event thrown by another thread.    Public Class asrMouseHover Public Event MouseIsHovering(ByVal sender As Object, ByVal e As System.EventArgs) Private _timer As System.Threading.Timer Private _xCoord As Int32 = 0 Private _yCoord As Int32 = 0 Public ReadOnly Property XCoord() As Double Get Return _xCoord End Get End Property Public ReadOnly Property YCoord() As Double Get Return _yCoord End Get End Property Sub New() Dim myTimerCallback As System.Threading.TimerCallback = New TimerCallback(AddressOf MyCallbackMethod) _timer = New System.Threading.Timer(myTimerCallback, Nothing, 1000, 1000) End Sub Sub MyCallbackMethod(ByVal s

Blob Cache Event ID 7888 Runtime Exception Thread was being aborted

HI, We have 3WFE and we are getting error Events 788 and 5538 on all three servers at same time. Any thoughts on what is causing this error? Event Type: Error Event Source: Office SharePoint Server Event Category: Office Server General Event ID: 7888 Date:  9/14/2010 Time:  2:31:08 PM User:  N/A Computer: MOSS2007A Description: A runtime exception was detected. Details follow. Message: Thread was being aborted. Techinal Details: System.Threading.ThreadAbortException: Thread was being aborted.    at System.Threading.ReaderWriterLock.AcquireWriterLockInternal(Int32 millisecondsTimeout)    at Microsoft.SharePoint.Publishing.BlobCache.<>c__DisplayClass14.<>c__DisplayClass17.<FetchItemFromWss>b__11()    at Microsoft.Office.Server.Diagnostics.FirstChanceHandler.ExceptionFilter(Boolean fRethrowException, TryBlock tryBlock, FilterBlock filter, CatchBlock catchBlock, FinallyBlock finallyBlock) For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.   Event Type: Error Event Source: Office SharePoint Server Event Category: Publishing Cache Event ID: 5538 Date:  9/14/2010 Time:  2:31:08 PM User:  N/A Computer: MOSS2007A Description: An error occured in the blob cache.  The ex

Raising PropertyChanged on a background thread.

What's the official word from Microsoft on raising the PropertyChanged event on a background thread for a property that's bound to a WPF gui? A couple blogs/sites say that the event is automatically dispatched to the UI thread. I am able to verify this in my own my own tests. I can bind to a property on a view model and then set the property on a background thread without issues. I am able to verify that the property setter is called on a background thread; yet, the UI updates without issues. An example property:   private Brush _background; public Brush Background { get { if (this ._background == null ) { this ._background = Brushes.Blue; } return this ._background; } set { if (this ._background != null ) { Debug.WriteLine(Application.Current.Dispatcher.CheckAccess() ? "On UI Thread" : "On Background Thread" ); this ._background = value; this .OnPropertyChanged("Background" ); } } } If I set this property on a background thread, all backgrounds on controls bound to this property will change without problems. Any official word on this behavior?  

Getting SPRequest object was not disposed before the end of this thread in SP document library event


I am using a sharepoint event listener attached to a document library to export files when they are added or modified. Here is a partial stack trace from the SP log for the SPRequest object was not disposed:

This SPRequest was allocated at    at Microsoft.SharePoint.Library.SPRequest..ctor()     at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)     at Microsoft.SharePoint.SPWeb.InitializeSPRequest()     at Microsoft.SharePoint.SPFile.GetFileStream(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew)     at Microsoft.SharePoint.SPFile.OpenBinary(SPOpenBinaryOptions openOptions)     at Extract.SharePoint.Redaction.IdShieldFileListener.HandleSharePointFileEvent(SPItemEventProperties properties, FileEventType eventType)

Here is basically the code in the HandleSharePointFileEvent:

    public override void ItemUpdated(SPItemEventProperties properties)

The paint event on form appears to be hijacking the thread in another form.


Hardware: GigaByte Motherboard with i5 4 core Processor

Development Software: VS 2008 Pro

Operating System: Windows 7 Pro

I have an application that displays five forms at start up.

  1. [Start ] about 300 PX wide opens all other forms on start.
  2. [Cluster ] has  a ListView, TelNet connection and a reference to a SerialPort Component on [Radio ].  This form has a mouse down event that populates and opens a dialog, [NewLogEntry ], which on load populates it's controls with data sent from [Cluster ].  [Cluster ] also writes data to [Radio ].SerialPort to set devices on [Radio ].  [NewLogEntry ] sends data to the data store and populates the ListView object on [Log ] before it closes.  [NewLogEntry ] also has a button containing the calculated bearing between the application users location and another point on the Earth.  Clicking that button writes the bearing to the reference that points to [Rotor ].SerialPort.  Upon closing [NewLogEntry ] sends it's data to the data store
  3. [Radio ] has many Buttons and a few GroupBoxes with a SerialPort Component connected to

Thread Performance: Resource Contention Concurrency Profiling in Visual Studio 2010


Visual Studio 2010 includes new resource contention profiling features that help detect concurrency contention among threads. We walk through a profiling investigation to demonstrate how you can pinpoint and fix resource contention problems in your code.

Maxim Goldin

MSDN Magazine June 2010

Thread Diagnostics: Performance Tuning with The Concurrency Visualizer in Visual Studio 2010


Understanding performance bottlenecks in multithreaded apps used to require significant instrumentation and analysis by expert developers. The Concurrency Visualizer in Visual Studio 2010 significantly reduces the burden of parallel performance analysis.

Hazim Shafi

MSDN Magazine March 2010

CLR Inside Out: Thread Management In The CLR


Getting the performance you want in concurrent applications is not as straightforward as you might think. See how common threading issues can affect your application.

Erika Fuentes and Eric Eilebrecht

MSDN Magazine December 2008

Editor's Note: new Thread(ReadEditorsNote).Start(); yourAttention.WaitOne();


Introducing the issue, Howard Dierking points out that you can't simply parallelize your code blindly if you expect to truly reap the benefits that parallelism promises.

Howard Dierking

MSDN Magazine October 2008

Pooled Threads: Improve Scalability With New Thread Pool APIs


The new threadpool APIs in Windows Vista and in the upcoming Windows Server 2008 provide advances that even native Windows developers can benefit from.

Robert Saccone

MSDN Magazine October 2007

Concurrent Affairs: Build a Richer Thread Synchronization Lock


In my last column, I showed the various thread synchronization mechanisms employed by the Microsoft® . NET Framework (see Concurrent Affairs: Performance-Conscious Thread Synchronization). I then examined the performance characteristics of all these mechanisms and determined that the Interlocked methods performed the best because the calling thread never has to transition to kernel mode.

Jeffrey Richter

MSDN Magazine March 2006

Concurrent Affairs: Performance-Conscious Thread Synchronization


In my career, I have architected and implemented many thread synchronization techniques. This has provided me with a lot of experience that has shaped the way I now think about thread synchronization problems.

Jeffrey Richter

MSDN Magazine October 2005

Basic Instincts: Thread Synchronization


My last three Basic Instincts columns have examined techniques for using asynchronous delegates and creating secondary threads. Those columns demonstrated how to introduce multithreaded behavior into your applications.

Ted Pattison

MSDN Magazine September 2004

.NET Column: The CLR's Thread Pool


How does the thread pool work in the CLR?

Jeffrey Richter

MSDN Magazine June 2003

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend