Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hm..What do you need in that case: One Thread calls DoThis some time in succession. Another can run DoThat at least t2 seconds after LAST calling of DoThat or the first one after last calling DoThat?</p> <p>I think, If your target platform is Win then It is better to use WaitableTimer (however, It is not realized in .NET but you can use It through API. You need to define those functions:</p> <pre><code>[DllImport("kernel32.dll")] public static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes, bool bManualReset, string lpTimerName); [DllImport("kernel32.dll")] public static extern bool SetWaitableTimer(IntPtr hTimer, [In] ref long pDueTime, int lPeriod, IntPtr pfnCompletionRoutine, IntPtr lpArgToCompletionRoutine, bool fResume); [DllImport("kernel32", SetLastError = true, ExactSpelling = true)] public static extern Int32 WaitForSingleObject(IntPtr handle, int milliseconds); public static uint INFINITE = 0xFFFFFFFF; </code></pre> <p>And then using It as follow:</p> <pre><code>private IntPtr _timer = null; //Before first call of DoThis or DoThat you need to create timer: //_timer = CreateWaitableTimer (IntPtr.Zero, true, null); public static void DoThis() { //Waiting until timer signaled WaitForSingleObject (_timer, INFINITE); DoStuff(); long dueTime = 10000 * 1000 * seconds; //dueTime is in 100 nanoseconds //Timer will signal once after expiration of dueTime SetWaitableTimer (_timer, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false); } public static void DoThis() { //Waiting until timer signaled WaitForSingleObject (_timer, INFINITE); DoOtherStuff(); long dueTime = 10000 * 1000 * seconds; //dueTime is in 100 nanoseconds //Timer will signal once after expiration of dueTime SetWaitableTimer (_timer, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false); } </code></pre> <p>And after using you may destroy timer by calling CloseHandle. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload