473,756 Members | 1,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

progress from Blocking method? or blocking main thread with async method??

hi ,

I'm in a slight dilemma.

I have an updater program that checks for pending updates and
downloads them if the users chooses to.

Since i dont need a windows form to check if there is an update , I
dont use a form unless i have two. This , creates either one of two
problems. When i'm downloading asynchonously , the main thread exits!
Or if use a blocked download , how do i display progress!?

In the updater.Downloa dUpdates() , i show a reusable ProgressForm ,
and update it in the downloadProgres s changed event, but it just shows
and nothing happens and the App never closes!?

[STAThread]
static void Main(string[] args)
{
Updater updater = new Updater();
if (updater.Pendin gUpdate)
{
Application.Ena bleVisualStyles ();
DialogResult result = MessageBox.Show ("There is an
update availiable , would you want to download and install it?",
"Updater", MessageBoxButto ns.YesNo);
if (result == DialogResult.Ye s)
{
updater.Downloa dUpdates(); // since the download
is threaded this just returns!?
}
}
else if (args[0] == "/shownot")
{
MessageBox.Show ("Hotel Management Studio is up to
date");
}
//do {} //this does'nt work!?
//while (updater.Comple ted);
}

Thanks so much

Gideon

Jun 19 '07 #1
2 2184
On Tue, 19 Jun 2007 07:30:19 -0700, giddy <gi*******@gmai l.comwrote:
[...]
Since i dont need a windows form to check if there is an update , I
dont use a form unless i have two. This , creates either one of two
problems. When i'm downloading asynchonously , the main thread exits!
Or if use a blocked download , how do i display progress!?

In the updater.Downloa dUpdates() , i show a reusable ProgressForm ,
and update it in the downloadProgres s changed event, but it just shows
and nothing happens and the App never closes!?
Somewhere in there, you need to wait until your progress status form
closes, and you need to close the progress status form when you're done,
as well as update it to show progress.

There are a variety of ways you could do this, but IMHO the most obvious
is to start with the basic template for a form-based application and
modify that. So, do the usual Application.Run () on the new form instance,
but in your case only if you need to do the update.

Once you have that in place, then there's question of how to interact with
your updater thread. You don't say how you've implemented it, but it
seems to me that the BackgroundWorke r class would work fine in this
instance. It provides well-defined mechanisms for all of the behaviors
you're looking for. In particular, progress notifications as well as
completion notification. In the completion notification, you can use
Invoke() to call some code that closes your progress form, and the
application will exit at that point (well, it will return from
Application.Run (), and that should naturally fall out of the Main()
method, exiting the application).

Pete
Jun 19 '07 #2
HI,

Thanks so much, Application.Run ()! thats all it needed!

Oh , i used the WebClient class inside the Updater class. It has a
DownfileAsync() and DownProgressCha nged and DownloadComplet ed events

Gideon

Jun 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12680
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run under the Compact Framework, which does not support Abort. Will Socket.Close cause the Receive method to finish, or is there a better way?
2
13389
by: Tash Robinson | last post by:
I have been searching and can not seem to find a good example of a working UDP client that listens, but does not block while waiting for data arrival. I am trying to write a client application that needs to listen on several TCP ports and one UDP port. It will send a start signal over UDP and then a repeated status message of a fixed length will be returned from the server. I need to listen to these messages, but I can't stop the...
7
17410
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the local or the remote endpoint from the client-side socket. The *really* strange thing is that Socket.LocalEndPoint is null. According to the doc, that's impossible: reading the LocalEndPoint
6
4125
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: Connect Receive response Send Connect ACK
3
2681
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD" listing in my address book and (optionally) their name listed on my "news" page of my birtle.com website (listed as "Jane Smith is a Programming GOD") for at least a month. Why not take a moment to read more and possibly boost your ego to all time...
9
3269
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my problem occurs when i try to show a progress bar. The screen freezes. I know i'm not the first one to ask about it. but i'm looking
3
8667
by: Ritesh Raj Sarraf | last post by:
Hi, I have a small application, written in Python, that uses threads. The application uses function foo() to download files from the web. As it reads data from the web server, it runs a progress bar by calling an install of a progress bar class. When using threads, I get the problem that the progress bar gets over-written by the download progress of files from other threads.
3
3290
by: Bob | last post by:
Hi, I have an app that has a 3rd party phone answering control (4 of ) (interfacing with dialogic 4 line card) attached to the main form. each control raises an event when its Dialogic line detects ring tone. I use the ring detect event handler to create a new thread which is given a reference to the control that is being rung. The called method then interacts with the control until the call finishes. My problem is that I believe I am...
1
20641
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call to WSACancelBlockingCall"
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9843
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.