Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Thread Problem

Thread Problem

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdata-structures
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sumit Domyan
    wrote on last edited by
    #1

    I am working on file based Messenger application (using VB.NET) in which i m using a Web Service where all my application functions are written. I have a list of users which i m desplaying in a treeview & refreshing this list every 5 seconds. I call a function from web service to get the latest list of online users. But i want to run this process in background using threads. But i m not able to do this. Code is: ---------------------------------------------------------------------------- Private populate_userlist_thread As Threading.Thread Private Sub RefreshUserList() 'This is my main function, here i m calling another function using thread. populate_userlist_thread = New Threading.Thread(AddressOf PopulateUsers) populate_userlist_thread.Start() End Sub 'Here is the delegate Delegate Sub GeneralDelegate() Private invoker As GeneralDelegate Private Sub PopulateUsers() Dim msngr_serv_obj As MessengerService.MessengerFunctions Dim users_dataset As DataSet Dim i As Int32 Dim curr_node As TreeNode Dim tree_node_collection As TreeNodeCollection msngr_serv_obj = New MessengerService.MessengerFunctions users_dataset = msngr_serv_obj.GetOnlineUsers UsersTreeView.Nodes.Clear() For i = 0 To users_dataset.Tables(0).Rows.Count - 1 If UsersTreeView.InvokeRequired = True Then invoker = New GeneralDelegate(AddressOf RefreshUserList) UsersTreeView.Invoke(invoker) End If curr_node = UsersTreeView.Nodes.Add(users_dataset.Tables(0).Rows(i).Item(0).ToString) curr_node.ForeColor = Color.Green Next End Sub ---------------------------------------------------------------------------- But this code is not working fine. Can anybody plz help me. Or do u have any other solution to this problem. Thanks Sumit Domyan Software Developer ANALEC INFOTECH

    F 1 Reply Last reply
    0
    • S Sumit Domyan

      I am working on file based Messenger application (using VB.NET) in which i m using a Web Service where all my application functions are written. I have a list of users which i m desplaying in a treeview & refreshing this list every 5 seconds. I call a function from web service to get the latest list of online users. But i want to run this process in background using threads. But i m not able to do this. Code is: ---------------------------------------------------------------------------- Private populate_userlist_thread As Threading.Thread Private Sub RefreshUserList() 'This is my main function, here i m calling another function using thread. populate_userlist_thread = New Threading.Thread(AddressOf PopulateUsers) populate_userlist_thread.Start() End Sub 'Here is the delegate Delegate Sub GeneralDelegate() Private invoker As GeneralDelegate Private Sub PopulateUsers() Dim msngr_serv_obj As MessengerService.MessengerFunctions Dim users_dataset As DataSet Dim i As Int32 Dim curr_node As TreeNode Dim tree_node_collection As TreeNodeCollection msngr_serv_obj = New MessengerService.MessengerFunctions users_dataset = msngr_serv_obj.GetOnlineUsers UsersTreeView.Nodes.Clear() For i = 0 To users_dataset.Tables(0).Rows.Count - 1 If UsersTreeView.InvokeRequired = True Then invoker = New GeneralDelegate(AddressOf RefreshUserList) UsersTreeView.Invoke(invoker) End If curr_node = UsersTreeView.Nodes.Add(users_dataset.Tables(0).Rows(i).Item(0).ToString) curr_node.ForeColor = Color.Green Next End Sub ---------------------------------------------------------------------------- But this code is not working fine. Can anybody plz help me. Or do u have any other solution to this problem. Thanks Sumit Domyan Software Developer ANALEC INFOTECH

      F Offline
      F Offline
      Fade Amit BS
      wrote on last edited by
      #2

      you are invoking 'RefreshUserList' from within the 'PopulateUsers' method :rolleyes: ? that can't be good... AND you should invoke ALL the GUI related methods by delegates as you did in usersTreeView.invoke(Invoker) otherwise strange things happen. Fade (Amit BS)

      S 1 Reply Last reply
      0
      • F Fade Amit BS

        you are invoking 'RefreshUserList' from within the 'PopulateUsers' method :rolleyes: ? that can't be good... AND you should invoke ALL the GUI related methods by delegates as you did in usersTreeView.invoke(Invoker) otherwise strange things happen. Fade (Amit BS)

        S Offline
        S Offline
        Sumit Domyan
        wrote on last edited by
        #3

        Thanks for reply amit. Actually the whole problem is i m calling Refresh userlist function every 5 seconds. should i destroy the previous thread before calling the function or not. Sumit Domyan Software Developer ANALEC INFOTECH

        F 1 Reply Last reply
        0
        • S Sumit Domyan

          Thanks for reply amit. Actually the whole problem is i m calling Refresh userlist function every 5 seconds. should i destroy the previous thread before calling the function or not. Sumit Domyan Software Developer ANALEC INFOTECH

          F Offline
          F Offline
          Fade Amit BS
          wrote on last edited by
          #4

          invoker = New GeneralDelegate(AddressOf RefreshUserList) UsersTreeView.Invoke(invoker) that's a code from the PopulateUsers() sub... unless i'm missing something this kind of action will create threads until something bad will happen , am i missing something :confused: ? i'll assume that either i am, or you have modified the code to invoke the RefreshUserList sub every 5. now i think that it might be best not the destroy the previously created thread, but to monitor it's existence, possible by using a global or shared boolean member probably named 'blRefreshingUserList', each time you enter your timer event, before you create a new thread check and see whether the previous one has finished. Although i don't see a scenario in which you won't finish refreshing in 5 secs. in 5 secs you can add A LOT or info, i think that something else is wrong, if you wold like to send me the code and tell me what you want it to do, i'll check it and see why it is not working. if not, you may also present more info so i can help you better, your choice (i won't steal your code anyway though) Fade (Amit BS)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups