I have a try/catch
block and within catch am trying to apply a pause but no matter what method I try (pause, threadsleep) it simply continues. and ignores all pauses in the mainblock. Is this a .NET bug?
catch (Exception ex)
{
if (maxDelay < 1)
maxDelay = 1;
newpause(maxDelay);
// Pause(maxDelay * 60);
Current = "Error:" + txt;
LogUpdater.UpdateLog(f, "Error sending : " + txt + ".");
System.Threading.Thread.Sleep(10);
bw.ReportProgress(1);
}
public void newpause(int maxDelay)
{
for (int i = 0; i < 60; i++)
{
System.Threading.Thread.Sleep(maxDelay*1000);
Application.DoEvents();
}
}
Your passing one/tenth of a second.
Your only passing 10 milliseconds, 1000 would be 1 second.
System.Threading.Thread.Sleep(1000); // One Second.
Please try running following code. It works on my side.
class PauseExample
{
static void Main(string[] args)
{
int a = 90;
int b = 0;
try
{
int c = a / b;
}
catch
{
Console.WriteLine("In catch");
System.Threading.Thread.Sleep(5000); //waits for 5 seconds
Console.WriteLine("Out of catch");
}
}
}
Let me know if this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.