Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 4 of 4

Load new map in separate thread to keep ui responsive?

This is a discussion on Load new map in separate thread to keep ui responsive? within the MapPoint Desktop Discussion forums, part of the Map Forums category; Anyone know how I can accomplish this? I don't like how my program freezes when I'm loading a new map. ...

  1. #1
    TicK is offline Junior Member White Belt
    Join Date
    Nov 2005
    Posts
    4

    Load new map in separate thread to keep ui responsive?

    Anyone know how I can accomplish this? I don't like how my program freezes when I'm loading a new map. Here's my attempt, can anyone tell me what I'm missing or what I should be reading up on?

    Code:
        
        Private Delegate Sub loadMapItem()
    
        Private Sub Thread1Work()
    
            Dim load As loadMapItem
    
            Dim Result As IAsyncResult
    
            load = New loadMapItem(AddressOf DelegateWork)
    
            Result = AxMappointControl1.BeginInvoke(load)
    
            Console.WriteLine("Thread 1 Done")
    
            Console.WriteLine(Result.IsCompleted.ToString())
    
            AxMappointControl1.EndInvoke(Result)
    
            Console.WriteLine(Result.IsCompleted.ToString())
    
        End Sub
    
        Private Sub DelegateWork()
    
            AxMappointControl1.Visible = False
            AxMappointControl1.NewMap(1)
            AxMappointControl1.Visible = True
            Console.WriteLine("Delegate Done")
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim Thread1 As Thread
    
            Thread1 = New Thread(AddressOf Thread1Work)
    
            Thread1.Start()
    
        End Sub

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    You dont tell us what the problem is !
    But you cannot use a visual component in a thread where it is not created in unless it is specially designed for that purpose using win32 CriticalSection.

    BTW, not only visual components, but the most of it...

  3. #3
    TicK is offline Junior Member White Belt
    Join Date
    Nov 2005
    Posts
    4
    Is it just me or does loading a new map take forever? (using axcontrol.newmap()). So you're saying it's not possible to thread the loading of the control so the program doesn't freeze up? Is it possible to speed this up somehow?

    Code:
        Private t As Thread
    
    
        Private Sub Thread1Work()
    
            AxMappointControl1.Visible = False
            t.Sleep(1000)
            AxMappointControl1.NewMap(1)
            AxMappointControl1.Visible = True
        End Sub
    
        Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            t = New Thread(AddressOf Thread1Work)
            t.Start()
    
        End Sub
    my second attempt has a little better results ...it at least gives it a chance to repaint my main window before the axcontrol.newmap() is called...

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    Is it just me or does loading a new map take forever?
    Can take up to a few seconds, depending on the speed of the machine even a douzan of seconds

    So you're saying it's not possible to thread the loading of the control
    No I did not say that. Euh maybe I did, but it was not meanth so (English is not my native language, so...). What I was trying to say is that it quite well possible that this works, but you will pretty sure go into troubles later because you are for sure doing an untested situation, and it is for sure not by design to be used as such.

    As general rule any component's methods should be called by the thread where it is created in, this includes the destroying of it. Unless the component is by design using CriticalSections to be called by several threads.

    For example there is no problem creating / using / destroying Mappoint object in a thread, but it can be a problem creating it in main thread and calling something from another thread.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Updating map in mapcontrol, through secondary thread
    By malkotian in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 08-16-2005, 02:44 PM
  2. Overlay two separate routes
    By jsfranks in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 07-20-2005, 09:46 AM
  3. Can't GetActiveMap from a Thread
    By discostu in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 06-08-2005, 07:25 AM
  4. is Mappoint thread safe
    By Wilfried in forum MapPoint Desktop Discussion
    Replies: 5
    Last Post: 04-06-2005, 01:50 PM
  5. I have the following set of data in a tab-separate....
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-26-2001, 06:26 PM

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
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26