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


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

WinForms and Multithreading

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :Windows Application
 
Hello, I tried to write WinForm application. I want to simulate long CPU operations by(Sleep(4000)) in new thread and change a TextBox value, after 4 seconds in this thread too. When I use BeginInvoke function from new thread it works, but program stop responding for 4 seconds. BeginInvoke method should be executed asynchronous so, interface shouldn't be blocked for 4seconds.   Sorry for my bad english. If you can, please help me.   CODE:   using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; namespace Watek1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { changeText(); } private void changeText() { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(changeText)); } else { Thread.Sleep(4000); textBox1.Text = "DONE"; } } } }  


View Complete Post


More Related Resource Links

C# Multithreading

  
In this article let us see aboutmultithreading. Multithreaded applications provide the illusion thatnumerous activities are happening at more or less the same time. In C#the System.Threading namespace provides a number of types that enablemultithreaded programming.

Threading in C#

MultiThreading with C#

  
In order to understand completely what is a thread, how and when to useit we should first see how Windows operating system works."Windows is a preemptive multitasking operation system

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.

Multithreading in .NET Applications, Part 3

  
Multithreading is a powerful design tool for creating high-performance applications, especially those that require user interaction. Microsoft .NET has broken down the barriers that once existed in creating multithreaded applications. The last two installments of the .NET Nuts & Bolts column were

Entity Framework 4 Tips for WinForms Development

  
I've been recently working on a smart client (WinForms) application backed by Entitiy Framework 4 (EF4) on Visual Studio 2010. In this blog post I will try to give you some tips regarding some limitations and points to be careful about EF4.

OpenMP and C++: Reap the Benefits of Multithreading without All the Work

  

Having more than one CPU core on a single chip makes a system with a processor with two cores operate just like a dual-processor computer, and a system with a processor with four cores operate like a quad-processor computer, so you get much better performance. But if your application does not take advantage of these multiple cores, you may not reap the benefits. OpenMP helps you create multithreaded C++ applications more quickly so the benefits of multithreading can be realized.

Kang Su Gatlin and Pete Isensee

MSDN Magazine October 2005


singleton class and multithreading

  

I have a singleton class thats used throughout an application.  The app will be multi threaded, each thread will access methods in the singleton class.  Is it best to create an instance of the singleton class at application startup then pass that into each thread, or is it safe to create an instance in each thread separately ?  (I check that no instance currently exists in the singleton class itself, so only 1 instance will ever be invoked)


Multithreading in c#

  

Hi,

Actually i want to upload a powerpoint file and do the conversion process(convert it to wmv) in the background so that i may not get blocked untill the process gets finished because it's a long process.How can i do that?Is ThreadPool can do that for me ?Any suggestions please ?


Winforms Updating UI Asynchronously Pattern - Need to Generalize

  
  Setup: Main MDI form with a progress bar and a label. Code in Main form.   public delegate void UpdateMainProgressDelegate(string message, bool isProgressBarStopped); private void UpdateMainProgress(string message, bool isProgressBarStopped) { // make sure we are running on the right thread to be // updating this form's controls. if (InvokeRequired == false) { // we are running on the right thread. Have your way with me! bsStatusMessage.Caption = message + " [ " + System.DateTime.Now.ToShortTimeString() + " ]"; progressBarStatus.Stopped = isProgressBarStopped; } else { // we are running on the wrong thread. // Transfer control to the correct thread! Invoke(new ApplicationLevelValues.UpdateMainProgressDelegate(UpdateMainProgress), message, isProgressBarStopped); } } Code in Child Form private readonly ApplicationLevelValues.UpdateMainProgressDelegate _UpdateMainForm; private void btnX_Click(object sender, EventArgs e) { _UpdateMainForm.BeginInvoke("StartA", false, null, null); try { if(UpdateOperationA()) { _UpdateMainForm.BeginInvoke("CompletedA", true, null, null); } else { _UpdateMainForm.BeginInvoke("Cance

Best approach to handle concurrent requests in winforms

  
I have a windows client application which would be used many users. This application submit requests to run a workflow (note that this is not a WWF or WCF service, its a class library thats gonna do some processing). What would be the best approach to code this? Would processing each request on a separate thread be a correct way? I am a newbie at this. PLease help. Thanks!

Best approach to handle concurrent requests in winforms

  
I have a windows client application which would be used many users. This application submit requests to run a workflow (note that this is not a WWF or WCF service, its a class library thats gonna do some processing). What would be the best approach to code this? Would processing each request on a separate thread be a correct way? I am a newbie at this. PLease help. Thanks!   

how to force my C# Winforms program run as administrator on any computer ?

  
hi how to force my C# Winforms program run as administrator on any computer ? and any kind of OS ? i need code solution (any sample code will be excellent) thank's in advance

How to prevent a C# Winforms program from appearing in Task Manager?

  
How to prevent a C# Winforms program from appearing in Task Manager?   thank's in advance

Winforms running in WPF solution loses XP style

  
We have a Winforms solution that we are converting to a WPF solution.  In our WPF solution, we add existing Winforms objects which works great.  My problem is when I compile and run the new .exe created from the WPF solution, my Winforms which appeared as XP style in the Winforms solution, now appears like the old Win95 style (buttons are square instead of rounded corners, etc.)... just kinda ugly. Is there some setting in the WPF solution where I can tell it to make my Winforms appear in the XP style? Thanks in advance for your help.

How to launch EULA.rtf for the end user agreement before the winforms setup project (installer) actu

  
Hi, I am using Setup Project to create installer for my windows applcation. I need to have the user read and accept to the terms in EULA document. So this has to be displayed BEFORE the installer installs the applciaiton. I tried adding the EULA file via Setup Project-> Application Folder -> Add -> File -> EULA.rtf assuming that installer will identify the license file by default and display it before installing the app, but it did not. Please Help.   Thanks

WinForms Controls under Windows 7

  
I have a small WinForms application which looks fine under Windows XP. When it's run under Windows 7 the controls look awful. The TabControl uses different sizing (horizontal/vertical dimensions) and tab spacing. The images in buttons are very small and lose definition. The CheckBox is very tiny. The height of the header row for DataGridView controls is very small, even though I have set an explicit height. Controls in a certain dialog box do not even work unless I "Disable visual themes" on the Compatibility tab of the application properties. I had carefully sized and aligned controls for a clean appearance under Windows XP. Windows 7 appears to have destroyed those efforts. What's going on and how can I restore the appearance to be as desired? Thanks!
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