Exemple #1
0
Fichier : Dde.cs Projet : mo5h/omeo
 /// <summary>
 /// Ensures that the function is being executed on the owning thread (which is the thread on which DDE has been called for the first time).
 /// </summary>
 internal static void CheckOwnerThread()
 {
     if (_threadOwner == 0)              // Invoked for the first time, remember the thread
     {
         _threadOwner = Win32Declarations.GetCurrentThreadId();
         Trace.WriteLine(String.Format("DDE has remembered thread “{0}”#{1} as its owning thread.", Thread.CurrentThread.Name, _threadOwner), "[DDE]");
     }
     else
     {                   // There's already an “own thread” recorded, check that it matches the current thread
         if (Win32Declarations.GetCurrentThreadId() != _threadOwner)
         {
             throw new InvalidOperationException(String.Format("DDE functions must be accessed from one thread only, the same one on which they were accessed for the first time (#{0} not “{1}”#{2}).", _threadOwner, Thread.CurrentThread.Name, Win32Declarations.GetCurrentThreadId()));
         }
     }
 }