Have you looked at BackgroundWorker component that is available in Win Form
designer's toolbox since VS2005?
It does exactly what you want: runs another thread from win form UI. You
simply use this component to kick off another thread to accessing database
and when the data access thread returns, you update the UI with data from
database.
"rockdale" <(E-Mail Removed)> wrote in message
news:b49db684-b972-4060-954a-(E-Mail Removed)...
HI, Patrice:
Thanks for the reply. The network available change event is very
helpful to my situation.
The ado.net async calls is also an interesting feature. But it is kind
not what I wanted.
The GUI is a thread - call it GUIthread, the appl will sprawl another
thread - let's call it DBthread.
Say if user clicked a button to retrieve data(suppose this will take a
very long time), instead of do the data retrieving in the GUIthread -
which the GUI will freeze to wait for the data to return. I want to
send an event/message to the dbthread let it does the data retrieving.
and now GUIthread still can respond to end user. once the dbthread
finished retrieving, the dbthread will send an event/message back
GUIthread, inform GUIthread that the data is ready, the GUIthread then
can process the data.
I do not know how to pass data (query parameters and query result)
between those 2 threads, I do not know how GUIthread can send an event/
message to signal DBThread to start the task.
in MFC world, we have PostMessage so it is not a problem to me.
In C#, I can see lot of samples using delegate, but I am not exactly
know how it works.
Again, thanks for the links. It is very helpful.
-Rockdale
On Oct 17, 12:35 pm, "Patrice" <http://scribe-en.blogspot.com/> wrote:
> Hi,
>
> > 1. Is there an easy way to detect that the network is disconnected.
>
> See :http://blogs.msdn.com/adarshk/archiv.../323162.aspxto test
> for
> network connectivity. You'll likely still have to what you do at this time
> for db connectivity (but in almost all cases I suppose it should work) as
> most often the real issue is the network not the db.
>
> > 2. When the network is broken and the appl tries to connect to the
> > database, it will take a long time to get the failed connection from
> > database. the GUI will not respond in this period. I am thinking using
> > another thread to do all the database work.
>
> It's likely a connection timeout. Testing for network first allow to
> prevent
> the db driver to run into this (unless the db is really unavailable
> because
> of some other issue).
>
> > 3. But, in C#, how do we implement this
> > kind of communication?
>
> Some more details could be needed. In general ADO.NET provides support for
> async db calls. Seehttp://msdn.microsoft.com/en-us/library/hz8wbs6k.aspx
>
> --
> Patrice