.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Imran Ghani
Post New Web Links

WPF Client App Freezing -- UI Thread Sleep, Wait, Join

Posted By:      Posted Date: October 15, 2010    Points: 0   Category :WPF
 
Okay, I need some help from the community -- I am about to lose my mind.

I have a .net 3.5SP1 WPF client app that allows field tickets to be written out in the field and synced, using sync services, to our production servers.

Here's the situation:


After my background worker threads have finished their work, the tip of the day goes away and the app freezes randomly a few seconds later.  I can only make it happen about 1 in every 20 times, if that. 

 

When I view in the debugger, it says the UI thread is "sleeping, waiting for join."  Now, background workers should all play cleanly with the UI thread.  So honestly I don't know if another thread is causing it - I actually even read a borderless Window (which would be my tip of the day screen) could cause it.  But I've removed that and tested and can still generate the issue.

 

I have tried to figure out what's causing this off and on for a month now and have had no luck.  I have removed what I think may be offending code, to only find out I'm still have the problem.  For example, I've removed a sync image, splash screen, code from background worker, etc.

 

If anyone has any tools to help identify what threads are hanging my U


View Complete Post


More Related Resource Links

Thread.Join in WPF on shutdown

  

Short version: How do I do thread.Join() in a WPF app without deadlocking the UI?

During the Window_Closing() this application shuts down various threads.  If the GUI calls .Join on them then the UI hangs and gets a deadlock as soon as something calls Dispatch.Invoke().  This happens when a thread tries to update the UI to indicate it was aborted.

What I need is something like the old MsgWaitForMultipleObjects() but in WPF fashion.  It is complicated by the fact that I'm not even sure it is safe or possible to process messages during a Window_Closing() event.

I'm looking for ideas...



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()
        Do
            System.Threading.Thread.Sleep(500)
            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?


Thanks



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));
  moveMotor.Start();
}

private void moveMotor(int time){
  //set bit to start motor to move
  Thread.Sleep(time*1000);
  //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

Thread.Sleep() issue

  

 Hello all -

 

I'm having an issue with thread.sleep, as I'm purposley trying to cause a 5 minute delay in a service oriented application I'm supporting.  When monitoring for a specific exception, I'm doing a Thread.Sleep(300000) statement.  300,000 milliseconds = 5 minutes, right?  Trouble is, the delays encountered are never 5 minutes, always less, and they vary, sometimes 30 seconds, sometimes 40 seconds, sometimes a full minute.  Anybody have any idea why?

Note:  I have my Thread.Sleep(300000) statement in a catch block where I'm monitoring for IOException, specifically a semaphore timeout, or not enough storage available.  Would this type of exception cause the thread.sleep() to behave sporadically like I described above?  Seems to always be consistantly a five minute delay as intentioned when tested elsewhere in my application.

Any insight would be appreciated!

Thanks

 

 


Why is Thread.Sleep() not interruped when it is in catch block?

  

Take a look at following simple code..
(This program is not meant to do some useful things. It's just for a demonstration purpose.)

class Program {
    private static void Main(string[] args) {
        // start new thread.
        Thread thread = new Thread(new ThreadStart(ThreadFunc));
        thread.IsBackground = false;
        thread.Start();

        // interrupt the thread.
        thread.Interrupt();
    }

    private static void ThreadFunc() {
        try {
            try {
                // assume something goes wrong...
                throw new Exception("TEST");
            }
            catch (Exception) {
         &nb

Can I use Thread.Sleep() instead of delay acitivity..

  
Basically I want to pause the activity for 20mins. I just simply use Thread.Sleep() method.. Should I use delay activity..
- What is the difference between Thread.Sleep() and delay activity..?

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

Client Side Gridview Pagination using JQuery

  
I would like to show how to use Client Side Gridview Pagination using Jquery Table Pagination Plugin by using Ryan Zielke.

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

To that end, I'm going to walk you through these four steps to effectively implementing a client side Repeater, using ASP.NET AJAX and jQuery:

Practical Multithreading for Client Apps

  
Writing applications that use multiple threads is often considered an advanced programming task, prone to errors. In this month's column, I'll focus on a practical application of multithreading in Windows® Forms applications with some real benefits, while attempting to keep things simple. My goal is to present multithreading in an approachable way that addresses a very common need: writing applications with a user interface that remain responsive to the user.

Use jQuery and ASP.NET AJAX to build a client side Repeater

  
By sending only data to the client, you can profoundly reduce the size of what you send and see a substantial increase in performance. You also allow yourself the ability to easily add features like light-weight sorting and paging on the client. This can not only improve your users' experience, but reduce server load and bandwidth requirements.

Adding Client-Side Confirmation When Deleting

  
The JavaScript confirm(string) function displays its string input parameter as the text inside a modal dialog box that comes equipped with two buttons - OK and Cancel (see Figure 1). The confirm(string) function returns a Boolean value depending on what button is clicked (true, if the user clicks OK, and false if they click Cancel).

want to execute url without showing that page or url to client.

  

hello friends,

I need ur help,what i want to do is to execute a url ("To send a text message to client") on client registration but without showing that url page, in short executing url without displaying any page or url to the client.

please help and thanks in advance.


Client script not running

  

Dear all,

in my MVC 2 application, and in the shared Master Page I wrote this little script for menu handling :

<script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script type="text/javascript"> $(document).ready(function () {   
       
     $('#nav li').hover(  
         function () {  
             //show its submenu  
             $('ul', this).slideDown(100);  
   
         },   
        function () {  
           //hide its submenu  
            $('ul', this).slideUp(100);           
         }  
     );  
       
 });</script>


The script, that shows menu items when the

Problem to obtain client IP on web service

  

Friends,

I'm having problems to obtain the client IP on web service. Here's my scenario:

One server with Windows 2003, hosting the web service using .Net Framework 2.0, with IP 10.0.2.50 and host name ServerTransaction.
Other server with Windows 2003, hosting a web application using .Net Framework 2.0, that consuming the web service on  ServerTransaction, with IP 10.0.2.51 and host name ServerApplication.
Many other computers on the local network (IPs: 10.0.2.80, 10.0.2.81, 10.0.2.82, ...) acessing the web application on ServerApplication.

On the code of the web service I've tried to use HttpContext.Current.Request.UserHostAddress or HttpContext.Current.Request.ServerVariables("REMOTE_ADDR") or HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FORR"), but always I can only get the IP of ServerApplication (10.0.2.51).

Any idea or tip?


Thanks and sorry for my bad english.


Smart Client: Building Distributed Apps with NHibernate and Rhino Service Bus, Part 2

  

Smart client applications are responsive and promote interactivity with the user. In this article, we continue building a smart client application using NHibernate for data access and Rhino Service Bus for reliable communication with the server.

Oren Eini

MSDN Magazine August 2010


Categories: 
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