|
-
Dec 18th, 2013, 05:08 PM
#1
Thread Starter
New Member
[RESOLVED] Having Trouble with Data Across Threads
I have been looking @ http://www.vbforums.com/showthread.p...d-Entry-Method
and i am thinking that that is something that will resolve my issue i just dont know how
basicly i have 2 forms
a main form
and then another settings form which i keep values for data
then i have a secondary thread sent from the main form to another class called Connection
from Connection i need to grab the values from the settings form.. or some global strings
as an example i have constructed a simple class
Code:
Public Class GlobalSettings
Public Shared Nick As String = SettingsForm.Nick_
End Class
inside of my form1
which grabs a global variable Nick_ inside of SettingsForm
this is not the only data i want to pass..its a bunch of strings i want to pass to connection but for now
i would clearly like to just get passed sending that one
i noticed someone in the link above talking about lambda functions to the alternate thread from start...if anyone can go a bit further into it i would love to know
but for now form1.GlobalSettings.Nick returns blank
SettingsForm.Nick_ returns blank
SettingsForm.NickName.Text returns Blank
from the seperate thread
thanks
-
Dec 18th, 2013, 05:27 PM
#2
Thread Starter
New Member
Re: Having Trouble with Data Across Threads
OK GUYS ..thanks for everyones help i have figured this out
http://www.vbdotnetforums.com/vb-net...arameters.html
i now can see values from my settings window passed to the alternate thread..hope this helps
-
Dec 18th, 2013, 05:45 PM
#3
Re: [RESOLVED] Having Trouble with Data Across Threads
I think that I disagree with the use of the settings form. Why have a form that serves only the purpose of passing data around?
However, since you called it SettingsForm.Whatever, it looks like you are using the default instance of the form. That won't work the way you expect for a form, because the default instance of a form is thread local. What this means is that if you access SettingsForm from some other thread, it is not the same instance of the form as you have in the UI thread. It's a different form with different data.
My usual boring signature: Nothing
 
-
Dec 18th, 2013, 06:21 PM
#4
Re: [RESOLVED] Having Trouble with Data Across Threads
I have to agree with Shaggy. You are abusing that SettingsForm. If you have a form where the user can view and edit settings then that's all it should be used for, i.e. the display and modification of settings. The settings themselves reside elsewhere. This will also solve many of your problems because you only have cross-thread issues because you're using a form. By using that SettingsForm, you're actually causing the problem, not solving it.
Unless you specifically need something that it can't provide, you should just use My.Settings for your settings. The only time the SettingsForm is used is when the user wants to view or edit the settings values. The form would get the values from My.Settings and pass any changes back to My.Settings. Any code that needs to use the settings also gets their values from My.Settings. There's no forms involved so there's no issue with what thread you access the data from.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|