Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Forms application hangs

Posted on 2006-06-13
3
Medium Priority
?
339 Views
Last Modified: 2009-12-16
Hi Experts!
I am programming an application that gets information of a company contract. The process is:

1- Connects to an XML web service to get data about a contract.
2- Makes an SQL database insertion with this information.
3- Opens Excel to do insertions and read outputs from a document.
4- Closes Excel
5- Shows information in a datagrid in the Windows Form.

When I run the process to get information for one contract, everything works fine. However, now I need to get information from multiple contracts, so I added a timer that fetches every contract in a listbox, runs the process for all contracts, waits 5 seconts and then repeats it again and again.

The application is hanging and crashes, no errors, it just hangs with the sandclock icon and stops working.

I was wondering if anyone had a clue on how to avoid this, maybe refreshing the form after every timer cycle? Code is big and divided in several classes so posting it here might be tricky.

Thanks

glopezz

0
Comment
Question by:glopezz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 750 total points
ID: 16896070
Your app is most likely stuck in your processing loop and is unable to process the messages necessary to keep the form responsive and painted properly.

Two options:

   (1) Spatter your loops with calls to Application.DoEvents()

        For x = 1 to y
            ...
            ...
            ...
            Application.DoEvents()
        Next x

    (2) Place your processing loops into another thread.
0
 

Author Comment

by:glopezz
ID: 16912735
Thanks Idle Mind,

I have tried the Application.DoEvents, seems to work!

Just before accepting the answer:

What about a Me.Refresh? Could this help too?

Also, do you have a good reference or link to try option 2 (process loops into another thread)?

Thanks

glopezz
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16912845
You would still need Application.DoEvents() to allow the Refresh() call to be processed...

    ...
    Me.Refresh()
    Application.DoEvents()
    ...

It gets more complicated when you thread things out because you are not supposed to update GUI components from a thread without using Delegates and the Invoke() methods.

Here is a simplified example...

(the worker sub can access anything in the class...but use Delegates to write/change to GUI components...Delegates are not necessary to READ GUI components though)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim T As New System.Threading.Thread(AddressOf Worker)
        T.Start()
    End Sub

    Private Sub Worker()
        ' do something...
        System.Threading.Thread.Sleep(5000) 'simulated five second work

        UpdateLabel(Label1, "threaded work complete")
    End Sub

    Private Delegate Sub LabelDelegate(ByVal lbl As Label, ByVal msg As String)

    Private Sub UpdateLabel(ByVal lbl As Label, ByVal msg As String)
        If Me.InvokeRequired Then
            Me.Invoke(New LabelDelegate(AddressOf UpdateLabel), New Object() {lbl, msg})
        Else
            lbl.Text = msg
        End If
    End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question