.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

GUI freeze when WorkerThread is set to sleep

Posted By:      Posted Date: October 27, 2010    Points: 0   Category :Windows Application

I have a windows forms application built in VS2010 which is responsible for running java scripts.

The scripts are running on a worker thread so the GUI can stay responsive and show log messages from the script.
while script is running, the GUI will loop:
while (!(m_endActionEvent.WaitOne(10, false))) //m_endActionEvent is an AutoResetEvent

During the execution, the script may call a .NET object to execute a delay command.
This is the method that is called:
public void Delay(int delayInMs)

After calling this delay command, the GUI freeze and stop responding to user or updating the log view.
After some investigation, I found that a weird way to wake up the GUI is to invoke a method, it may be any method.
I changed the delay function:
public void Delay(int delayInMs)
this event will call a function that belongs to the main form class:
public void WakeUpGUI()
    CrossThreadOperation.Invoke(this, () =>

View Complete Post

More Related Resource Links

DataGridView freeze columns issue

When i try to freeze a column that is off screen (to the right) when the DataGridView's (DGV) first displayed column is the first column in the DGV, the DGV refreshes and displays the DGV from the first column in the DGV. Also, the horizontal scrollbar on the bottom of the page disappears.  This means that i cannot see the unfrozen columns and i cant get over to view the column that I froze. This seems to behave differently from freezing a column in Excel, which freezes the columns you are currently viewing at that moment (not sending you back to the first row) and then the scroll bar applies to the frozen columns like normal. Is there a workaround for this? I tried setting the first displayed index for the column and I get an exception. I'm using .NET 3.5 on an XP machine.

how to Freeze specific columns in GridView

My question is how to freeze specifi columns of Gridview control ?Freeze means...for example say if we are freezing the first column of grid then on scrolling a horizontal scroll bar of the grid will scroll all columns other than the first column. That means the first column will be visible always without any movement. But the first column should move if we use the vertical scroll bar. thanks is advance satish  

Problem using sleep

I am developing a small sample web application which contains 2 textboxes t1, t2 and a button b1. On the click event of b1  i want it to display a text "hello" on t1 and after a delay of 5 seconds text on t2 "bye".how to do it.i'm a newbie to asp.netthnks in advance

why is the caret freeze?

good day to the experts, My form have several maskTextbox and a text box, one of the masktextbox is my starting point of editing and or adding upon clicking add button or edit button.  i put this code at the add/edit button mskDateTime.Enabled=true; mskDateTime.Focus(); mskDateTime.SelectionStart = 0; My problem is the caret wil freeze at the selected masktextbox upon entry, i have to hit the ENTER key twice before i can change the value?.  Sometimes when i hit the ENTER key, the pop-up at the FORM'S icon will shows up,  It seem's that i lost the focus of the form? or at the textboxes? thanks for any explanation regarding this error .madix_t

Windows 7 - Takes forever to wake up from sleep mode

I check the event viewer (under applications) and see this error message: The remote name could not be resolved: 'HTC-media'   at System.Net.HttpWebRequest.GetResponse()    at MSSConnectorService.MSSLongPoller.Poll()   I think this was from my HP media server, but I was getting the same slow wake up time before I got the server?  Could this be the cause?  I have a Gigabyte UD4P-55A motherboard running windows 7 64-bit, 8 GB RAM, and a ATI 5750 graphics card with the latest drivers installed.  Please advise.  Thanks.    

Application Freeze

Hi, I have some questions regarding the Form.ShowDialog() method in C#. Can you tell me what are the possible reasons that can cause it to freeze? Or what can prevent the a dialog from being loaded into memory? (no OutOfMemoryException thrown). I have some code snippets below:     public class OrderForm : Form { private static OrderForm self; public static OrderForm OrderEntryForm() { if (self == null) { self = new OrderForm(); } return self; } private OrderForm() { InitializeComponent(); this.Load += new EventHandler(onLoad); } private void onLoad(object source, EventArgs args) { Console.WriteLine(source.ToString()); } private void cmdBack_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; } private void cmdTakeout_Click(object sender, EventArgs e) { Hide(); } } public class RegistrationForm : Form { public RegistrationForm() { InitializeComponent(); this.Load += new EventHandler(onLoad); } private void onLoad(object source, EventArgs args) { Console.WriteLine(source.ToString()); } private void button1_Click(object sender, EventArgs e) { // code for begininvoke here (delegates ShowOrderForm) } private void ShowOrderForm() { OrderF

How do you freeze the tablix header row in an Excel export file in SSRS 2008?

So this is totally killing me. I've found out how to make a tablix header row repeat on each page of a PDF export file in SSRS 2008 (which I won't even get started on because all I can say is that 2005 is way better), but I cannot figure out how to make a simple header row of a tablix freeze in an Excel export file.  The tablix is right at the top of the body and spans the entire width of the design area.  How in the world do you get it to freeze in the Excel export file?

wpf grid freeze a row

Hi there,I am developing a wpf application which has the wpf grid. I have used the GridSplitter to split the grid columns; if I change the grid column size using the splitter i need to resize the controls in the wiondow based on the column width. Is there any way to identiy the grid splitter moving (I could not find a event in grid splitter for its moving)?Alternatively, Is it possible to have a row in wpf grid as a freezed row (i.e. it should not scroll down and up in the grid which is inside the scrollviewer)?Thanks in advance,Sekar

Make a T-SQL Query Sleep for a certain amount of time

At times, in test scenarios, you may want to emulate that a transaction or a T-SQL query takes 'x' amount of time. Well that is possible (although not with precision) in SQL Server (2005/2008) using the WAITFOR command.

Freeze Minesweeper window positiom

I want to fix the minesweeper window to a specific location on the screen when I execute it.  Can this be done easily.   Don Jacobs

Workflow designer causes VS 2010 RTM to freeze when editing build process template.

I have a Dell Studio 1747 laptop with Intel i7 1.6GHz, 6GB RAM, Windows 7 Professional x64. I recently "updated" VS 2010 RC to RTM (removed all of RC and installed RTM). So far so good. Also, I have TFS 2010 RTM on the machine working perfectly, and have two team projects in there. Now, on a given solution, I copied DefaultTemplate.xaml to NewDefaultProcessTemplate.xaml and checked it in. I check it out and open it, and the workflow designer shows up. Then, I "Expand All" and go down to the "Compile, Test, and Associate Changesets and Work Items" section. If I click a subsection to collapse it, the mouse cursor changes to an hourglass and stays like that indefinitely. Sometimes, after a couple of minutes, the action is performed; then, it happens again up to a point where VS completely freezes. I have cleared VS 2010 cache, and have performed a repair on VS 2010 and TFS 2010 (just in case) to no avail. I have even disconnected from TFS right after openning the file, and still the same issue. This is f****** extremely frustrating. I can't do anything on the workflow designer. HELP !!!!!

Freeze the Excel headers in SSRS 2008/ 2008 r2

Hi, How can i freeze the headers while exporting the report to excel? will this works in ssrs 2008 / 2008 r2? thanks in advance...    -- Sathish

How to Freeze page header SSRS 2008


Hi All,

Can someone tell me how to repeat page header on each page, i am using SSRS 2008.

Thanks in advance.

.NET application crashes when computer system wakes up from sleep mode.


Need help in understanding this error message generated from mscorlib failing when using threading.  I know the problem is not the code written by me, as the application works fine until the computer system is left idle, say for 30mins and allowed to go into sleep mode then the error manifests itself, about a minute later when the computer wakes from sleep mode, the application will perform its tasks and then this error is generated.

This could be a problem with System.Net.NetworkInformation.NetworkChange.AddressChangeListener.AddressChangedCallback

Any information given about the error described below is greatly appreciated, and information on how to prevent such errors even more greatly appreciated, or traps and handles it successfully.


Kind Regards,


Details of the error given below:--


"The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone)."

Source: "mscorlib"

StackTrace: "   at System.Threading.SynchronizationContextSwitcher.Undo()\r\n   at System.Threading.ExecutionContextSwitcher.Undo()\r\n   at System.Threading.ExecutionContext.run

TCPClient and Read not returning complete data unless I use thread.sleep


Hello experts, here is my code that I have a question on:

 Dim receivedbyte(1024) As Byte
        Dim myread As Integer = 0
        Dim myresponsesb As New StringBuilder()
            myread = myns.Read(receivedbyte, 0, receivedbyte.Length)
            myresponsesb.Append(System.Text.Encoding.UTF8.GetString(receivedbyte, 0, myread))

        Loop While (myns.DataAvailable)

In the above, myns is a networkstream that is initialized with a tcpclient that is communicating with a XMPP server. basically, iam getting back xml messages.

The issue with the above is that if I dont use thread.sleep(500), the complete data is not returned. Why is that? I have tried to use a streamreader instead of read and using that method i can get complete data from the stream. What am I doing wrong with the Read method of networkstream?

SECOND: The XML being returned from the server is not well formed - the closing tag for one of the tags is missing and I am unable to use XDocument to parse this XML because of this. What could be the issue here? Is it my code or something on server end?

Also, what technique should i use to make the returned XML well formed so that I can use XDOCUMENT and LINQ to parse this?


long Thread.Sleep causes thread to exit


I have a WPF application where a user enters a time in seconds and clicks a button. Clicking the button causes a thread to start which sets a bit in an external device and after the amount of time entered by the user has elapsed the bit has to be set to 0.

This application controls a stepper motor. So for example if the user enters 5 seconds then a bit is set in the motor which makes it start moving and after 5 sec the bit is reset which makes the motor stop moving. An example of the code I have written is as below

private void btnMoveMotor(object sender, RoutedEventArgs e){
  int time=Convert.ToInt32(txtTime.Text);
  Thread moveMotorThread=new Thread(()=> moveMotor(time));

private void moveMotor(int time){
  //set bit to start motor to move
  //reset bit to stop motor

Sometimes the user can enter a very long time (like 300 seconds) and this causes my thread to exit before the 300 seconds have elapsed. I know th

MediaElement - Video freeze after Ctrl+Alt+Delete is pressed



Why do my video frozen when I do Ctrl+alt+delete and go back to the WPF application? Any idea?

string videoSource = "somevideofile";
MediaElement HomePageVideo;

void init()
  HomePageVideo.Source = new System.Uri(videoSource);

  HomePageGrid.IsEnabled = true;
  HomePageGrid.IsHitTestVisible = true;
  HomePageGrid.Opacity = 1;
  HomePageGrid.Visibility = Visibility.Visible;


void play()
   HomePageVideo.Position = new TimeSpan(0, 0, 18);

<Grid Name="HomePageGrid" Visibility="Hidden" Background="Black" Opacity="0">
  <MediaElement Name="HomePageVideo" Width="1280" Height="720" LoadedBehavior=
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