According to http://forums.asp.net/t/1809557.aspx/1[^], the problem arises by using the wrong protocol: Dim de As New DirectoryEntry("GC://DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
replace that with Dim de As New DirectoryEntry(@"LDAP:\\DC=us,DC=myCompany,DC=com", "myDomain\MyAdminUsername", "myPassword")
This question is a new post prompted by my other thread, "The old DoEvents and UserControls". I created a separate thread here, since it is branching off from the old discussion.
In the other thread, it was looking like converting code from supporting DoEvents, to supporting threading might be a big rewrite. But now I am not so sure. I downloaded an example Pause/Resume Thread program from online and that program had a separate class that was threaded. It then communicated to the main form via a delegate.
But I wanted to find out if it was possible to do threading of a procedure that was NOT in a separate class...But one residing in the main form's class, like any other sub. The reason this was important to me, was to cut down on the amount of code rewriting by keeping my existing code in place, and merely adding on additional code to thread one of those main form procedures. My revision to that original threading example seems to say, "yes", to that question. Here is my version of that little demo. It simply runs a counter that counts from 1 to whatever, and when the thread is suspended, the counter halts, until resumed. Since I am new to threading, is there anything wrong with this idea that could end up biting me in the rear?
Here is the code:
'Form1 controls:'Button1: Starts/Resumes thread execution.'Button2: Suspends thread execution.'txtResults: Textbox for count results.'Quit_cmd: End program.'Define a delegate type for the form's DisplayValue method:PrivateDelegateSub DisplayValueDelegateType(ByVal txt _
'Declare a delegate variable to point to the form's'DisplayValue method:Private m_DisplayValueDelegate As DisplayValueDelegateType
Private m_Thread As Thread
'This value is incremented by the thread:Public Value AsInteger = 0'Add the text to the results. The form provides this 'service because the thread cannot access the form's 'controls directly:PublicSub DisplayValue(ByVal txt AsString)
txtResults.Text = txt
'txtResults.Select(txtResults.Text.Length - 1, 0)EndSubPrivateSub Form1_Load(ByVal sender AsObject, _
ByVal e As System.EventArgs) _
'Make a new counter object:Dim new_counter AsNew Counter(Me, my_number:=1)
'...is the same as:'Dim my_number As Integer = 1 'The thread number.'Dim new_counter As New Counter(Me, my_number)'Make the thread to run the object's Run method:
m_Thread = New Thread(AddressOf new_counter.Runno)
'Make this a background thread so it automatically'ends when the form's thread ends:
m_Thread.IsBackground = True
Button1.Enabled = False
Button2.Enabled = TrueEndSubPrivateSub Button1_Click(ByVal sender AsObject, _
ByVal e As System.EventArgs) _
If (m_Thread.ThreadState And ThreadState.Unstarted) _
<> 0Then'The thread has never been started. Start it:
Else' The thread is paused. Resume it:
m_Thread.Resume() 'THIS HAS BEEN DEPRECATED!!!EndIf
Button1.Enabled = False
Button2.Enabled = TrueEndSubPrivateSub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
'Suspend the thread:
m_Thread.Suspend() 'THIS HAS BEEN DEPRECATED!!!
Button1.Enabled = True
Button2.Enabled = FalseEndSubPublicSub DoSomething(ByVal m_MyForm As Form1, _
ByVal m_DisplayValueDelegate _
For loopo = 1To10000000'Wait 3 seconds:
'Lock the form object. This doesn't do anything to the'form, it just means no other thread can lock the form 'object until we release the lock. That means a thread'can update m_MyForm.Value and then display its value'without interference:SyncLock m_MyForm
'Increment the form's Value:'m_MyForm.Value += 1
m_MyForm.Value = m_MyForm.Value + 1'Display the value on the form. The call to 'InvokeRequired returns True if this code is not'running on the same thread as the object m_MyForm.'In this example, we know that is true so the call 'isn't necessary, but in other cases it might not'be so clear:If m_MyForm.InvokeRequired() Then'Invoke the delegate:
EndSubPrivateSub Quit_cmd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
EndEndSubEndClass'This class's Run method, Runno(), displays a count in the 'Output window.PublicClass Counter
'The form that owns the Value variable:Private m_MyForm As Form1
'Define a delegate type for the form's DisplayValue 'method:PrivateDelegateSub DisplayValueDelegateType( _
ByVal txt AsString)
'Declare a delegate variable to point to the form's 'DisplayValue method:Private m_DisplayValueDelegate As DisplayValueDelegateType
'This counter's thread number:Private m_Number AsIntegerPublicSubNew(ByVal my_form As Form1, _
ByVal my_number AsInteger)
m_MyForm = my_form
m_Number = my_number 'The thread number.'Initialize the delegate variable to point to the'form's DisplayValue method:
m_DisplayValueDelegate = AddressOf _
EndSub'This procedure is directly addressed for threading. This'test is to see whether or not a form1 Class's procedure'called from here can respond to a thread pause. In other 'words, does a threaded procedure's pause also apply to any 'calls it makes, regardless of what class those calls 'reside within? Can the pause immediately go into effect 'if it is applied when the program is presently running 'that call?'The upshot is, yes it can...Kind of. The call certainly 'was paused, but the Thread.Sleep(3000) line was unaffected 'and kept counting regardless of everything else being in a 'paused state. So you have to be careful not to assume that'certain functions will necessarily respond to a thread 'pause, especially timers, stopwatches, etc., unless the 'thread pause/resume state can be used to affect those 'objects.''IMPORTANT: The thread pause action was able to occur 'immediately while the Thread.Sleep(3000) line was still 'suspending execution. So even though it kept counting for '3sec after the pause was initiated, it still allowed the 'pause to go into effect:'Also, THE CALLED SUB IS NOT IN THE SAME CLASS AS THE 'THREADED PROCEDURE.PublicSub Runno()
TryCall Form1.DoSomething(m_MyForm, m_DisplayValueDelegate)
Catch ex As Exception
'An unexpected error:
Debug.WriteLine("Unexpected error in thread " & _
m_Number & vbCrLf & ex.Message)
I wanted to find out if it was possible to do threading of a procedure that was NOT in a separate class
No need to test. Yes, you can thread just about any code you want. A form is just a class, like any other.
The reason this was important to me, was to cut down on the amount of code
rewriting by keeping my existing code in place, and merely adding on additional
code to thread one of those main form procedures.
Wrong approach. If your going to go through the trouble of threading the code, scrap what you have and do it write instead of trying to Frankenstein a solution together.
But the example program I showed does basically what I'm suggesting. So it doesn't SEEM like a kludge. Especially since all I basically have is one procedure that I need to thread, and everything else is called from it sequentially. So from a performance point of view, it all has to work sequentially anyway, so my only benefit from threading is to have the ability to pause execution at will, which was the primary reason to begin with. Is that a reasonable enough reason for doing it that way? I don't see any future versions of this program gaining any other benefits from threading.
I want to connect my VB.NET application to the data saved on my webserver's mysql database. Can you please tell me, is it possible or not? Can you give me any hint for further coading? Where should i look for help in this regard?
Or should I consider other language for this pupose?
I want users to fill their info on online php form, this info get saved in mysql database. Now i want to insert this info in the .net application's database installed on client's computer.
I am curious about a problem I am having with DoEvents. Now, I know DoEvents() is old school, and was only included in vb6 because vb6 did not support threading, at least not without a lot of difficulty. But the problem I have, is that I have ported a vb6 program over to vb.Net and there were a fair amount of DoEvents() lines due to a bunch of loops. These DoEvents lines were necessary because I had a Pause button that needs to stop execution when the user desires it.
This worked OK in .Net, too...Until I included a TreeView usercontrol. Now, a fair amount of time is spent in the usercontrol since as the program scans folders, the TreeView is constantly updating to show the progress. In itself, that is a very inefficient way to show progress due to the amount of time processing the TreeView updates. But it looks rather cool as it progresses and I want to keep that look. The problem is that, I know that threading is the way to handle interruption of processing, but on the other hand, I just want this thing running as quickly as possible with the DoEvents lines...I can switch over to threading at some later date.
But no matter where I put the DoEvents lines, they do not let the Pause button Click event to fire. My question is, does entering a usercontrol cause DoEvents in the stack to get cleared out? Or does it simply disregard any DoEvents lines altogether, whether they are inside the user control or not?
All DoEvents does is process any pending windows messages sitting in the apps window message queue. It's not a second message pump, but it does suspend everything in the UI thread and handles the remaining messages, then it lets UI thread processing resume as normal.
There is a difference though. The old VB6 DoEvents called Thread.Sleep, where as the .NET implementation does not.
I'd serisouly consider scrapping the DoEvents stuff as soon as possible and transfer the long-running work to either background threads, BackgroundWorker, or Tasks. Doing so will take a considerable rewrite of your code.
Doing so will take a considerable rewrite of your code.
That is exactly what I am concerned about. I am trying to get out a v1 with as much speed as possible, w/o rushing to miss errors in the code.
Dave Kreskowiak wrote:
All DoEvents does is process any pending windows messages sitting in the apps window message queue.
That is where my question lies, and I am just as much academically interested in why it is not working, as I am trying to get v1 out the door.
Since the Pause button click is an event, DoEvents SHOULD catch that event sitting in the stack waiting to be processed. Unless something is throwing it out. Could the problem be that every time I pass through the usercontrol, any DoEvents processed there for the Pause button in the UI are ignored? In other words, in trying to get my UI's Pause button to respond to DoEvents in the usercontrol, is it of no use in the usercontrol since it is occurring inside a different class and not the general UI where the Pause button is located?
The problem is in the code that is looking for the flag to tell it to pause.
The convesion from VB6 to .NET does NOT guarantee that the code is going to run like it did under VB6. Hell, it's not even guaranteed to compile!
The problem does not appear to be with DoEvents, but with the code that you're trying to pause. Since we know nothing about that code and when the "pause" button does, it's impossible to say waht's going on.
The Pause button click event is not even firing to set the flag, except when the program is currently in my Form1 class, where that button is located. That is what it SEEMS like, anyway. My take on it is that when I try the Pause button while execution is inside the treeview usercontrol, (where execution seems to be spending the majority of its time under certain conditions) the button's click event can't fire because the program is not currently in Form1 to process it.
When I notice this the most, is when the treeview is cycling through a bunch of files in some folder, one after the other. If a file does not meet a certain set of criteria, it immediately moves to the next file in the folder, and this occurs rapidly. Since the treeview must update for every change in node selection for every file, the code is spending a lot of time in the usercontrol just spitting out updates to the treeview. I think that is when my Pause button Click event fails to fire. And I mean explicitly that...I can put a breakpoint in the button's Click event, and it never triggers.
When a scan of the treeview completes, the Pause button responds immediately.
When I notice this the most, is when the treeview is cycling through a bunch of
files in some folder, one after the other. If a file does not meet a certain set
of criteria, it immediately moves to the next file in the folder, and this
So does this code have a DoEvents in it that gets called kind of frequently??
I tried DoEvents every which way I could...In every loop and inside the usercontrol. My impression is that the ones in the usercontrol never work at all. The ones in the main form work when they can get a breather...That is, when execution is not currently inside the usercontrol code.
To make sure, I ran my own tests on DoEvents in a UserControl and it does work. The problem has to be somewhere else as far as I can tell. Again, we can't see your code, so it's impossible to tell you what's going on.
Dang. I was afraid of that. I think i buggered it up!
I'm going to have to go through it with a fine tooth comb, and figure out what I did, then. Which may just be an exercise in understanding something I will never use again. As I research threading more, there might be a reasonably easy way of making the transition to it.
PublicFunction GetElMaster() As IQueryable(Of Ems_ElMasterClass)
Protected Sub gvElMaster_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvElMaster.SelectedIndexChanged
I get empty text from all the cells
Development envirunment is:
- VS 2012
- Asp.net 4.5
- CodeFirst aproach
Hello Friend I am making a GUI for my vpn in visual basic and I am getting a problem when I am using
("perl something.pl" + somehting + something1 + something2)
but when I am using
("perl something.pl something1value something2value")
everything is working fine any solution please
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim IP As String = "xxx.xxx.xxx.xxx"
Dim Username As String = "root"
Dim Password As String = "mypassword"
Dim cmd As Renci.SshNet.SshCommand
Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(IP, Username, Password)
Dim sshClient As New Renci.SshNet.SshClient(connInfo)
Dim something As String = TextBox1.Text
Dim something1 As String = TextBox2.Text
Dim something2 As String = TextBox3.Text
cmd = sshClient.RunCommand("perl something.pl" +something + something1 + something2)
Label1.Text = cmd.Result
Last Visit: 19-Sep-20 12:14 Last Update: 19-Sep-20 12:14