.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

C# wait for x seconds

Posted By:      Posted Date: October 03, 2010    Points: 0   Category :.NET Framework
I need an app to wait for x seconds. How can I implement that?

View Complete Post

More Related Resource Links

How do I wait for 10 seconds before doing a response.redirect?

I want to wait for 10 seconds before doing a response.redirect("test.aspx") to another aspx page.

So how should I do it?

a few seconds wait


hi guys,

I am trying to write a site where you can download stuff. I would implement the following scenario:

1. user clicks on a download button

2. it redirects him to a new page

3. download will start but after a few seconds (the number of seconds left will be displayed).

how to make the last bit, how to start download after a few seconds and also put this info in a label?

thanks in advance

Bugslayer: Wait Chain Traversal


Windows Vista has a new API called Wait Chain Traversal (WCT), which allows you to determine when and why a process is deadlocked. Read on.

John Robbins

MSDN Magazine July 2007

Windows 2000: Asynchronous Method Calls Eliminate the Wait for COM Clients and Servers


Windows 2000 is the first version of COM to support asynchronous method calls, which permit clients to make nonblocking calls to COM objects and objects to process incoming calls without blocking the calling threads. COM clients benefit from asynchronous method calls because they can continue working while waiting for outbound calls to return. Objects benefit because they can queue incoming calls and service them from a thread pool. Our SieveClient and SieveServer sample apps demonstrate how to create and use asynchronous clients and servers in COM-based distributed applications.

Jeff Prosise

MSDN Magazine April 2000

can anyone tell me why setInterval is not working properly i want to display the time every seconds,

setInterval is suppose to execute the script every second there getting the most uptodate time of day , but it does not update it stays the same
      <script type="text/JavaScript">

          function interval() {
              setInterval("time()", 1000);
          function time() 
              var d = new Date();
              var time = d.getHours();
              var time2 = d.getMinutes();
              var time3 = d.getSeconds();

              document.write(" : ");
              document.write(" : ");
  // -->
      <input type="button" OnClick="interval()" value="Click Me!"/>


How to wait for a Serial Port to respond

Hi Is it to possible to wait for a serialPort component to complete it's response?  I have a device connected to the serial port of my PC. I use the serialPort component in order to communicate with the device. I have to send 2 different strings of data to the serial port but the trick is that after sending the first string of data I have to wait for the serial port to respond. Then I have to check the response and decide whether I must send the second string or not. Also after sending the second string, I have to check also the response of the serial port. I tried to use an arbitrary amount of wait time between the sending of the two strings. Something like SerialPort.Write(...) ; Thread.Sleep(2000); SerialPort.Write(...); But the software failed when I tried it in a slower PC. So is there a way to replace the Thread.Sleep(2000) with a command that will wait until the serial port complete its response? Although, the response of the serial port is different between the two sending strings, I do know that the first response is only one byte and I know the ending byte of the second response. Also, the second response is no more than 30 bytes in length. Regards Dimitris

How to convert seconds to HH:MM:ss format

Write a C# program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (for example, if the elapsed time is 9630 seconds, then the output is 2:40:30.)Can anyone pls help me!!Im using visual studio 2005

Execute Command and wait until finished (WMI - ManagementClass)

Hi allI am trying to execute a command on a remote maschineand wait until the command is finished.I can start the process but I do not know how to wait for finish.Thanks for any comment !!!Best regardsFrankHere is what I am doing            System.Management.ConnectionOptions local_Connection = new System.Management.ConnectionOptions();            local_Connection.Username = "some_user";            local_Connection.Password = "some_password";            local_Connection.Authority = "ntlmdomainome_domain";            // ManagementScope erstellen            System.Management.ManagementScope local_Scope = new System.Management.ManagementScope("\\\\servername\\root\\CIMV2", local_Connection);            local_Scope.Connect();            // ManagementClass erstellen            System.Management.ManagementClass local_ClassInstance = new System.Management.ManagementClass(local_Scope, new System.Management.ManagementPath("Win32_Process"), null);            // Create a results and completion handler            System.Management.ManagementOperationObserver local_ClassHandler = new System.Management.ManagementOperationObserver();            // Invoke method asynchronously            System.Management.ManagementBaseObject local_InParams = local_ClassInstance.GetMethodParameters("Create");            local_InParams["CommandLin

Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential cau

Attempting to upgrade from SQL 2005 EE to SQL 2008 EE on Vmware ESX 3.5 virtual server. below is info from Detail.txt related to successful install with failures... 2010-09-02 13:50:46 Slp: Sco: Attempting to check if file 'D:\Data\MSSQL.1\MSSQL\LOG\ERRORLOG' exists 2010-09-02 13:50:46 Slp: Sco: Returning security descriptor O:BAG:SYD:AI(A;ID;FA;;;S-1-5-21-3788118842-658835432-3441893140-1006)(A;ID;FA;;;S-1-5-21-3788118842-658835432-3441893140-1007)(A;ID;FA;;;BA)(A;ID;FA;;;SY)S:AI(AU;IDFA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD) 2010-09-02 13:50:46 Slp: Configuration action failed for feature SQL_Engine_Core_Inst during timing ConfigRC and scenario ConfigRC. 2010-09-02 13:50:46 Slp: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes. 2010-09-02 13:50:46 Slp: Configuration action failed for feature SQL_Engine_Core_Inst during timing ConfigRC and scenario ConfigRC. 2010-09-02 13:50:46 Slp: Microsoft.SqlServer.Configuration.SqlEngine.SqlEngineConfigException: Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes. 2010-09-02 13:50:46 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.SqlServerServiceBase.WaitSqlServerStart(Process processSql) 2010-09-02 13:50:46 Slp:    at Microsoft.SqlServer.Configuration.SqlEngine.SqlServerServiceSCM.StartSqlServer(St

Wait for an activity to complete?

I have the following scenario:My workflow (Workflow1) has a custom activity which inserts data into the database.My program creates an instance of WorkflowApplication (passing an instance of Workflow1) and runs the instance.Thereafter, it reads the data that has been inserted in the execute method of my custom activity. How do I know that the execution of the activity is complete? I am running in issues as the workflow instance seems to run on its own thread.Code snippet:Program.cs  // create the WF instanceActivity wf = new WorkflowTests.MicroLoanOrignation(); WorkflowApplication instance = new WorkflowApplication(wf){                PersistableIdle = OnIdleAndPersistable,                Completed = OnWorkflowCompleted,                Idle = OnIdle}; instance.Run(); //Gets data here..//Enters into this code block before the Execute method of the lst activity of the workflow is complete How do I make it synchronous. I have have tried BeginRun and EndRun methods on the WorkflowApplication - but the Run method merely schedules the workflow to run as per https://connect.microsoft.com/VisualStudio/feedback/details/509928/workflow

PollingDuplexHttpBinding Client Channel Faults unexpectedly after few seconds

Hello, i have a Silverlight 4 application which communicates using Http Polling Duplex to an IIS 7, .NET 4 WCF Service (actually two of them, in the same app). I am obviously taking advantage of the callback features provided by this type of solution. Setup has been performed by following these documents: Service setup: http://msdn.microsoft.com/en-us/library/cc645027%28v=VS.95%29.aspx Silverlight setup: http://msdn.microsoft.com/en-us/library/ee844557%28v=VS.95%29.aspx All has been working fine until yesterday, when i went on upgrading the Silverlight Tools for VS2010 to version 10.0.30319.352 which has also upgraded my Silverlight runtime to 4.0.50826.0 . Running my app now, after few seconds from the first call to the services, the client inner-channel faulted event fires on both proxies without an apparent motivation (exception, user interaction, etc.). What i have been able to notice, by analyzing connections with Fiddler, is that as soon as the open connection to the service which holds a callback channel receives a response, the client-side proxies fail. I'll try to show how the HTTP connections appear to behave: Call to the first service, callback channel retreived, immediate response 200 OK, no content Call to the second service, business logic performed, immediate response 200 OK, no content Call to the first service, no response for a few seconds, response 200 OK

How to Wait for the Completion of the BookmarkCallback method?

Hi I have a custom activity, which create a bookmark. In the callback method, I am setting some data to the object, which I need back to host application. It is just like protected override void Execute(NativeActivityContext context) { context.CreateBookmark(EventName, new BookmarkCallback(this.HandleEvent));} private void HandleEvent(NativeActivityContext context, Bookmark bookmark, object obj) { if (obj != null) { Dictionary<string, object> dat = obj as Dictionary<string, object>; dat.Add("NewValue", "value1"); } } From the host, I am resuming the bookmark as workflowApp.ResumeBookmark("Next", data); if (data.ContainsKey("NewValue")) { newValue = data["NewValue"].ToString(); } ResumeBookmark will execute only when the WorkflowApplication goes Idle; so I am not getting the value back just after the ResumeBookmark. How can I wait for the Completion of the ResumeBookmark? I tried with the BeginResumeBookmark() & EndResumeBookmark() methods too. EndResumeBookmark() doesn't mean that the callback method execution is completed. Either, I need to make the WorkflowApplication to go Idle state or I need to wait for the completion of the ResumeBookmark(Callback method completion). Note:  We are using the UI thread for executing the workflow          &n

How to run multiple methods asyncronously and wait until all are finished?

I have this method:   public virtual List<User> GetUsersAsync(string[] usernames) { var result = new List<User>(); foreach (var username in usernames) { result.Add(this.GetUser(username)); } return result; }   Currently this method and GetUser run synchronously. How can I change this so that each GetUser runs asynchronously and GetUsers returns when all the GetUser() requests are completed? I know one way would be using delegate beginInvoke and endInvoke like this:   public virtual List<User> GetUsers(string[] usernames) { var result = new List<User>(); var delegates = new Dictionary<GetUserDelegate, IAsyncResult>(); // begin invoke all asynchronously foreach (var username in usernames) { var thisDelegate = new GetUserDelegate(GetUser); var asyncResult = thisDelegate.BeginInvoke(username, null, null); delegates.Add(thisDelegate, asyncResult); } // end invoke all foreach (var thisDelegate in delegates) { result.Add(thisDelegate.Key.EndInvoke(thisDelegate.Value)); } return result; }   this does work but seems to be a bit ugly code; what is the better way to do this? Thanks  

Show Please Wait... message on loading GridView.

Hi All. I wants to show Please Wait... message on loading GridView. I am not using ajax. The Please Wait... should come above the GridView. On combobox value change the gridview binds with new value. On every binding i wants to show the Please Wait... above the gridview.   Thanks.

Excecution of wait for field change in current item action

Hi everybody, I've an SharePoint designer WorkFlow with two simple actions: wait for field change in current item (wait for the aproval status was approved) update item list(set a value to a field in the current item) how immediate is the execution of an workflow like this by the WF Runtime engine?, how it works? would be possible that WF runtime engine take time to execute this tasks, how much is waranteed acording the WF architecture? The Previous question becouse this solution is composed by an smart document and a workflow: -A workflow that have to copy the aproval status  to a field when this was aproved. -The document have to detect the change on the field value(seted by the workflow) when the document is closed by the user(this action could be executed just after the user approve). In conclusion the document depends from the workflow execution to detect the change, if the workflow were not executed "immediately" document actions would not be executed when the document were closed. by the above I need to know how reliable is this workaround and make a choice, this workaround or an event handler controling the itemupdating event(synchronous event) to do the tasks made by the workflow. Suggestions are welcome! PD and Background: The smart document(with managed code) is the template associated to the content type in a document library. The Current

Showing thousands of rows in datagrid, need cursor to wait while loading rows

I´m creating DataGrid columns dynamicly in C# and loading data into a list at the same time. Cursor is waiting at the same time. Now, after columns are created and data is loaded into a list. I set the myDataGrid.Itemssouce = mylist; Cursor=Curosrs.Arrow; Andafter that, I set the Cursor to arrow again as you can see. But when the list contains thousands of rows it takes about 5-10 seconds for the datagrid to show the rows. Its ok but I need the cursor to be in waiting stage allso while data is not shown but the cursor is not waiting, its arrow. Any suggestions, please?
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