.net - VB Cross-thread Shared (static) Member Access?

Aug 4, 2010

I'm a newbie to threading, trying to learn it as I go. don't make any assumptions and try to explain threading concepts and rules that might seem obvious. I have a Module (Static class) as follows:

Module Main
Private ReadOnly _dbConn As SqlClient.SqlConnection
Public ReadOnly Property DBConn() As SqlClient.SqlConnection
Get
Debug.Print("Accessing DBConn")

[Code]...

All throughout the application, when i access DBConn on the same thread, it works as expected. howeve, later on I created a background worker that tries to access DBConn and nothing happens, the thread just hanges (the Background worker). I dont get the printout and the application doesnt continue. the background worker thread doesnt continue past that point, and so the thread never exits. I dont get any exceptions, and i Cant debug in Visual Studio (visual studio hangs).I guess its a 2 part question: why cant i access DBConn from the other thread, and why does it hang without giving me a threadAccess exception? also, why does visual studio hang (I'm assuming it hanges because the thread is hanging)?

Please Note: I am not asking about practice. I know I shouldnt be sharing the same connection, rather returning a new connection. in this particular application it is safe since (although i execute it on a background thread) as per the flow of the application, the connection can only be accessed one at a time. I just want to know why it hangs accross the thread.

View 1 Replies


ADVERTISEMENT

C# - Access A Shared/static Member Through An Instance Variable?

Mar 3, 2011

Here's an example of what I'm talking about...

Public Class Sample1

Public Shared Function MyValue() As Integer
Return 0
End Function
Public Sub Code()

[Code]...

Me.MyValue gives a warning in VB.NET and (the equivalent code gives) an error in C#. Is there a particular reason for this? I find it more intuitive/natural to access the shared function using 'Me.MyValue' - but I avoid it to keep my warnings at 0. Did someone else just decide 'Nah, it makes more sense to do it the other way' or is there some technical reason I don't understand?

EDIT: I was thinking of it wrong, more like a 'sub class' in OOP. Even if something is declared in the base class, you access it through the instance you have. But that relationship is not the same with shared or static.

View 6 Replies

Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

Jun 2, 2011

how do I overcome it? I have created a class and compiled into .dll This code

[Code]...

View 2 Replies

Access Of Shared Member - Constant Member - Enum Member Or Nested Type Through An Insta

Aug 13, 2009

In Visual Studio 2008, if I do this:

[Code]....

Does anyone here know how to get the above to work WITHOUT warnings being generated?

View 4 Replies

Warning 1: Access Of Shared Member, Constant Member, Enum Member Or Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated

May 31, 2010

In the following code i get a warning at line 59:Warning 1: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.and.. At line 78 I get this Warning:

Warning 2 Property 'SelectedCustomer' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

The program compiles and runs well, but i cant' undesrtand the reason for these warnings. Any Idea ?

1: Public Class Form1
2:
3: 'Form level members
4: Private objCustomers As New ArrayList

[code]....

View 5 Replies

Singleton Class Or Shared (static) Member Functions?

Aug 9, 2011

I would like to understand the Pro & Cons in using the commonly used methods via Singleton class against Shared (Static) members of a class in VB.Net. It could be in terms Time, Space complexity or best practices. I have a BankAccount class with methods doing some business logic.

GetBalance()
GetLast5Credits()
GetMiniStatement()

[code].....

View 4 Replies

VS 2005 Access Of Shared Member, Constant Member, Enum Member?

Apr 28, 2011

Cannot appear to be able to get this function to not have the above error.Private Function GetIncidentActions(ByVal FromAgentID As Integer, ByVal ToAgentID As Integer, ByVal incidentAction As Integer, ByVal ActionDate As Date) As String

[Code]...

View 10 Replies

Access Of Shared Member, Constant Member, Enum Memberor Nested Type Through An Instance; Qualifying Expression Will Not Be Evaluated?

Jun 23, 2009

i changed a class variable to shared so i can access it in all instances of the class, but it caused an error. what is causing this, and how can i fix it?

Private
Shared img As Bitmap
Me
.img = bgImage

View 2 Replies

Forms :: Thread Cannot Access Another Thread's Member Directly And UI Updating

Oct 18, 2011

I have a small problem that I am sure is due mostly to my inexperience with threading. I have used simple entirely self-contained threads before, but not to a great extent. I understand the basic laws that surround them, such as how a thread cannot access another thread's member directly, and must use delegates.

[Code]...

View 1 Replies

Access Of A Shared Member, Blah?

Aug 2, 2011

I've used .NET for a long time but I've never really been sure of this warning :-"Access of a shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated"Whilst this is not causing an issue and I've not really experienced this problem a lot with my own code, converting some code from an old .NET project gives 10's of these errors.

Code:
Protected Function GetContentTypeFromString(ByVal TypeString As String) As MailContentType
Select Case TypeString.ToLower

[code]....

View 3 Replies

Access Of Shared Member Through Instance

Nov 6, 2009

After I formatted my laptop and reinstalled Visual Studio 2005, I receive a lot of same error as below message.
"Access of shared member through an instance; qualifying expression will not be evaluated"
If I click the error, it direct me to the line and all 102 error suggest me to add "Windows.Forms." before "DialogResult.OK". Should I add something on "Reference"?

View 4 Replies

Access Shared Member Through Type?

Nov 29, 2011

I'm wondering if this is possible. In my Test function below I want to

Check if T is of type BaseClass; throw an error if it's not.
Get the value of SomeText property of BaseClass.
Class BaseClass

[code].....

View 2 Replies

Cross-Thread Method Access?

Jan 29, 2009

I've got a problem. I'm running a different thread. The thread's sub is looping, doing various things during the program, and eventually tries to close the form. I get an error, because the other thread can't access the "Me" object, I guess. It won't close the form. I don't want to use Application.Exit. Is there another way?

View 3 Replies

Access Of A Shared Member [...] In Custom Class?

Jun 9, 2012

I have a custom class called "Time" with the following function, for determining if one Time equals another Time.

Public Shared Shadows Function Equals(ByVal Time1 As Time, ByVal Time2 As Time) As Boolean
Dim x(2) As Integer
x(0) = CInt(Time1.Hour)
x(1) = CInt(Time1.Minute)

[code].....

Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.I know it shouldn't do any harm, just let the compiler skip evaluation, but is it a way of getting rid of this warning?

View 6 Replies

Enumeration Warning Access Of Shared Member?

Oct 5, 2011

I created an enumeration in a class library... and compiled it into a dll

Public Enum TestEnum
x = 0
End Enum

I then imported this reference to a windows form project as a referenced dll Public Class Form1 Dim mytestenum As TestPublicEnum.TestEnum Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[Code]...

View 5 Replies

Access Of Shared Member ... Qualifying Expression May Not Be Evaluated

Jun 22, 2010

re: Access of shared member constant member enum member or nested type through an instance qualifying expression may not be evaluated I understand that this warning means that you should not reference a shared member via an instance. However, in my test case Test2.t.x("3"), I don't understand why it thinks I'm using an instance, since t is also a shared member. Also, note Test3. See what happens when you change declaration of GetObject() As Object to As Test3. I think I understand the behavior (not eval'd until runtime)

[Code]....

View 2 Replies

VS 2010 Cross Thread Access Of Serial Port

Mar 29, 2012

In my project I'm trying to send data to Serial port. I have added the serial port control to the form. Now if I try to send data to serial port using Serialport1.write method in a button click event, I'm able to send the data successfully to the serial port. Otherwise if I try to send the data using the same "Write" method from another thread other than the one in which the serial port component was created, I'm getting an exception saying serial port busy.

View 1 Replies

VS 2010 Error - Cross-Thread Operation Not Valid: Control TbPlaca1 Accessed From A Thread Other Than The Thread It Was Created On

Aug 13, 2010

In one application, I need use 4 simultaneous threads.When the threads finished, I need to update the text of a TextBox.So, I create 4 Textbox, and I wanna the threads change the text to FINISHED.Each thread change one distinct TB.I use this "example"

Dim Terminados As Integer = 0
Private Sub frmEnviarMensagem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Start()

[code]....

The problem is, I have an error in the red lines.The error is: INVALIDOPERATIONEXCEPTION "Cross-Thread operation not valid: Control tbPlaca1 Accessed from a thread other than the thread it was created on."I don't use cross threading. Each TB only was accessed for the correspondent thread, and for the "main program".

View 3 Replies

Cross-thread Operation Not Valid: Control 'Panel1' Accessed From A Thread Other Than The Thread It Was Created On." ?

Nov 3, 2011

This is the error message I am getting:

"Cross-thread operation not valid: Control 'Panel1' accessed from a thread other than the thread it was created on." The reason I am getting this error is because I am opening up a new form and then calling these three things:

Panel1.Show()
Label1.Show()
Label2.Show()

why I get this error message because it doesn't occur normally if I open Form2 after closing Form1, it only occurs when I open Form2 after closing Form4.

View 4 Replies

Error - Cross-thread Operation Not Valid: Control 'txt1' Accessed From A Thread Other Than The Thread It Was Created On

Jul 21, 2009

I have done a program using vb2005 to display reading from my microcontroller bs2 board but have encountered some problems. My code are as follows.

Dim Stop_Rx As Boolean
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
SerialPort1.Open()

[code]....

I've encounter an error which is, (Cross-thread operation not valid: Control 'txt1' accessed from a thread other than the thread it was created on.)

View 7 Replies

Error : Cross-thread Operation Not Valid: Control 'l_users' Accessed From A Thread Other Than The Thread It Was Created On

Jun 21, 2012

When my client try to connect to server I'm getting this error : Cross-thread operation not valid: Control 'l_users' accessed from a thread other than the thread it was created on.

Private Sub _socketManager_onConnectionAccept(ByVal SocketID As String) Handles _socketManager.onConnectionAccept
l_Users.Items.Add(SocketID)
End Sub

View 3 Replies

Cross-thread Operation Not Valid: Control 'Autocad' Accessed From A Thread Other Than The Thread It Was Created On

Jun 6, 2010

I have written an application that loads a form - frmCad as well as AutoCad. It does this via a class which detects when AutoCad quits.

Friend Class CadApp Private WithEvents AppObject As AcadApplication... Private Sub AppObject_BeginQuit(ByRef Cancel As Boolean) Handles AppObject.BeginQuit RaiseEvent Quit() End SubEnd Class

My main class loads frmCad as well as CadApp.

Public Class Cad Private WithEvents frmCad As CadForm Private WithEvents app As CadApp... Public Sub ShowForm() If frmCad Is Nothing Then frmCad = New CadForm frmCad.Visible = True End Sub... Private Sub app_Quit() Handles app.Quit frmCad.Dispose() frmCad = Nothing .... End Sub

When I debug the program, it stops at frmCad.Dispose()The program continues to execute, but all the code after it fails to work.Looking more carefully I get an error message which contains:-Cross-thread operation not valid: Control 'Autocad' accessed from a thread other than the thread it was created on.

View 4 Replies

Cross-thread Operation Not Valid: Control 'label2' Accessed From A Thread Other Than The Thread It Was Created On?

Feb 9, 2011

My error:Cross-thread operation not valid: Control 'label2' accessed from a thread other than the thread it was created on. I want to be able to give my Public RunBot() sub access to edit Labels, buttons, etc without an error.

[Code]...

View 8 Replies

Cross-thread Operation Not Valid: Control 'lblStatus' Accessed From A Thread Other Than The Thread It Was Created On

Apr 1, 2010

I'm getting the 'System.InvalidOperationException' error on acccessing a thread from other than where it was created. My code is:

'Required by the Windows Form Designer
Public components As System.ComponentModel.IContainer ' changed from private

[code]....

View 3 Replies

Cross-thread Operation Not Valid: Control 'statusHO' Accessed From A Thread Other Than The Thread It Was Created On

Jun 6, 2009

My problem is Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on.

System.InvalidOperationException was unhandled
Message="Cross-thread operation not valid: Control 'statusHO' accessed from a thread other than the thread it was created on."
Source="System.Windows.Forms"
StackTrace:

[Code]...

i used it and it works fine then. but as it is mentioned its not a good practice to use it. So what should i do? is it ok if i use this as i am not able to use correct practice. Mine application is not for enterprise purpose. its just my class project, and it works fine even if i put application working in background. System works ok. I dont know how to correct this error.As i dont have that much knowlege of threads.

So please guide me how to fix this in correct way otherwise i am force to go for bad programming practice
Please refer to Windows Mobile Developer Center > Smart Device Development Forums > Windows Mobile Development > Appendtext not working for all my code details

View 1 Replies

Cross-thread Operation Not Valid: Control 'lv1' Accessed From A Thread Other Than The Thread It Was Created On?

Aug 4, 2009

Cross-thread operation not valid: Control 'lv1' accessed from a thread other than the thread it was created on.

Dim lvi As ListViewItem
For Each lvi In lv1.Items

[code]....

View 1 Replies

Error Saying "Cross-thread Operation Not Valid: Control 'lblOnline' Accessed From A Thread Other Than The Thread It Was Created On."?

Feb 7, 2011

Ok i have a Form with the following

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtNotepad.Text = LoadFile("notes.txt")

[code].....

View 12 Replies

"Cross-thread Operation Not Valid: Control 'TextBox1' Accessed From A Thread?

Sep 18, 2009

When i run the program i am getting the following error in this line TextBox1.Text &= "File Created: " & FullPath & vbCrLf"Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on."

View 13 Replies

Cross-thread Operation Not Valid Control 'FormSplash' Accessed From A Thread Other?

Sep 5, 2009

I need your help on the following. In debugging mode only the program is stopping to the following line "My.Forms.FormMain.HelpProviderMain.HelpNamespace = "Reports.chm"" with the following error ""An error occurred creating the form. See Exception.InnerException for details. The error is: Cross-thread operation not valid: Control 'FormSplash' accessed from a thread other than the thread it was created on.""

I noticed that when I am putting NONE in SPLASH screen option in the properties of the project, there is no problem.I am no familiar with treating that's why can you give me detail instruction how to overcome this annoying problem?

View 1 Replies

Cross-thread Operation Not Valid Exception In Single Thread Application?

Nov 14, 2009

I am getting this exception: Cross-thread operation not valid: Control 'TextBoxOutput' accessed from a thread other than the thread it was created on. in a VB 2008 Windows Forms application that I havent specifically made multi-threaded. I have create a sub called Out() like this:

Private Sub Out(ByVal inString As String)
Me.TextBoxOutput.Text += (Me.TextBoxOutput.Text & inString & vbNewLine)
Me.TextBoxOutput.SelectionStart = Me.TextBoxOutput.Text.Length
Me.TextBoxOutput.ScrollToCaret()
End Sub

and I call it from various events to log messages I am getting from my pbx, which I use a third party open source dll to access. The interesting thing to me is that if I run the deployed application (ie, not in the VS IDE) I do not get any exceptions, it's only from within the IDE.if I add the line: Control.CheckForIllegalCrossThreadCalls = False to the form's constructor, the exceptions stop, but a) this seems like a hacky way to get around the issue and b) the application seems to hang sometimes when I have it set this way.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved