DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Forms and threading

  1. #1
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18

    Forms and threading

    I have a database type application with a master form (MDI parent) and a numer of child forms.
    One of the forms is a list of items which, when clicked on, open another form showing detail. If the user changes that detail, the form with the list needs to reflect these changes. I do from the details form by looking for the list form in My.Application.OpenForms and calling a public update function. The problem I have is that this can be slow, especially if the list in the list form is long.

    I am trying to do this operation with another thread, in the background from the detail form. When I try and do this, I get a cross threading error in the list form. Being new to threading, how do I do this, or is there a completely different way of handling this?

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663

  3. #3
    Join Date
    Nov 2008
    Posts
    23
    I would just reference the "list" form on the "detail" form. This can be done using a property or a custom constructor on the "detail" form. Then you don't have to search the "list" form out at all, just use the reference.

  4. #4
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18
    Finding the form is not a problem. The main issue I have is that, when I update the details form, it waits for any underlying forms to update before allowing the user to continue. What I would like to happen is for the list form to update in the background and not hold up proceedings on the details form. Threading seemed to be the logical path.

  5. #5
    Join Date
    Jul 2008
    Location
    Perth
    Posts
    18
    Thanks, the link gave me a much better insight on how to solve my problem. Moving the tread call to the "list" form seems to work.

  6. #6
    Join Date
    Nov 2008
    Location
    Mumbai
    Posts
    2

    Use a singleton object and define events which are triggered from the forms

    There are scenarios where one would like to share data or objects and their states accross multiple forms in a windows application. A clean way of achieving this is creating a singleton object which would persist across all your forms.

    Lets take an example :

    We have a collection of employee objects which gets updated in a particular form, and simultaneously the changes needs to get reflected accross multiple forms

    We create a seperate class (Singleton_Employees) which would hold the employee objects collection, this class would render only one object per application and should be instantiated from your main form (may be an MDI).

    Whenever you make changes to the employee objects collection this should be through the Singleton_Employees class - object.

    The singleton_employees object should define an event called Data_changed, this event should be delegated to a method in all the forms where the singleton_employees object is used.

    This would allow you to keep a single location of holding data as well as notifying all the places where you use it whenever changes occur.

    Let me know if this solves your problem, If required I can share a sample code.

Similar Threads

  1. Threading and CCRP Timers
    By lucbrunet in forum .NET
    Replies: 0
    Last Post: 06-08-2006, 09:47 AM
  2. Threading and the .NET Datagrid
    By McCleud in forum .NET
    Replies: 2
    Last Post: 08-01-2002, 10:54 AM
  3. Re: vb.net threading
    By Zane Thomas [.NET MVP] in forum .NET
    Replies: 5
    Last Post: 02-06-2002, 11:43 AM
  4. Replies: 2
    Last Post: 10-17-2001, 12:49 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center