|
treddie wrote: 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.
treddie wrote: 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.
|
|
|
|
|
Hey guys,
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?
[Project Details:]
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.
|
|
|
|
|
Hi again.
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?
Many thanks for any help on this.
|
|
|
|
|
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.
|
|
|
|
|
Dave Kreskowiak wrote: 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.
|
|
|
|
|
treddie wrote: 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.
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.
|
|
|
|
|
Can anyone please compress the following code? This code is used to make the text property of radiobuttons in a groupbox display values from columns of a dataset.
For Each rad As RadioButton In GroupBox1.Controls
If b > 1 Then
rad.Text = ds.Tables("AddressBook").Rows(a).Item(b)
b = b - 1
End If
Next
a = a + 1
For Each rad As RadioButton In GroupBox2.Controls
If c > 1 Then
rad.Text = ds.Tables("AddressBook").Rows(a).Item(c)
c = c - 1
End If
Next
a = a + 1
For Each rad As RadioButton In GroupBox2.Controls
If d > 1 Then
rad.Text = ds.Tables("AddressBook").Rows(a).Item(d)
d = d - 1
End If
Next
|
|
|
|
|
i can loop through the rows in a dataset using the code below. But how can i loop through the individual items of the same row.
For Each myControl As Control In Me.Controls
If TypeOf myControl Is GroupBox Then
For Each rad As RadioButton In myControl.Controls
rad.Text = ds.Tables("AddressBook").Rows(b).Item(c)
Next
b = b + 1
End If
Next
|
|
|
|
|
Hi,
I'm not able to get the cell value for the selected row in the gridview, the code in the aspx page:
<asp:GridView runat="server" ID="gvElMaster" PageSize="5" Width="100%" ItemType="EMS.Ems_ElMaster"
DataKeyNames="ElMasterID" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
SelectMethod="GetElMaster" HeaderStyle-VerticalAlign="Middle"
HeaderStyle-HorizontalAlign="Center" CaptionAlign="Top" CellPadding="4" GridLines="None" ForeColor="#333333"
OnSelectedIndexChanged="gvElMaster_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:DynamicField DataField="ElName" />
<asp:DynamicField DataField="ElStartRegDate" />
<asp:DynamicField DataField="ElEndRegDate" />
<asp:DynamicField DataField="ElDate" />
<asp:CommandField ShowSelectButton="True" SelectText="Select" CausesValidation="False" InsertVisible="False" ShowCancelButton="False"></asp:CommandField>
</Columns>
</asp:GridView>
code behind:
Public Function GetElMaster() As IQueryable(Of Ems_ElMasterClass)
Return _db.DbSet_ElMasters
End Function
Protected Sub gvElMaster_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvElMaster.SelectedIndexChanged
MsgBox(gvElMaster.SelectedIndex)
MsgBox(gvElMaster.SelectedValue.ToString)
MsgBox(gvElMaster.SelectedRow.Cells(1).Text)
MsgBox(gvElMaster.SelectedRow.Cells(2).Text)
MsgBox(gvElMaster.SelectedRow.Cells(3).Text)
End Sub
I get empty text from all the cells
Development envirunment is:
- VS 2012
- Asp.net 4.5
- CodeFirst aproach
Thanks for the help
|
|
|
|
|
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
sshClient.Connect()
cmd = sshClient.RunCommand("perl something.pl" +something + something1 + something2)
Label1.Text = cmd.Result
End Sub
End Class
|
|
|
|
|
All of your textbox values are being smashed together.
If the user types param1 in TextBox1 and param2 in TextBox2, your command line will look like this:
perl something.plparam1param2
You're not putting spaces between the command line parameters.
|
|
|
|
|
I appreciate your help but how to put spaces them because if I am giving spaces between the commands they are getting back in from once again.
|
|
|
|
|
cmd = sshClient.RunCommand("perl something.pl " + something + " " + something1 + " " something2)
Use the best guess
|
|
|
|
|
Thanks my problem is fixed now
|
|
|
|
|
Hi all.
I have a question about program performance. I have a ton of loops all over the place, and a pause button to pause execution. The pause button is pretty much useless right now as it gets superceded by what I figure are long-winded loops. In an attempt to locate the problem loops, I ended up placing temporary DoEvents lines in all of them. The idea was to see if I could get better performance out of the button. Then, I could remove the majority of those DoEvents that did not impact performance all that much. Unfortunately, all that work resulted in no better performance at all for the button. So I have two questions:
1. Is there some utility that can pinpoint where the majority of a program spends its time, without placing timers or stopwatches everywhere.
2. Are their certain events or API functions that can essentially "shut-down" DoEvents lines?
Thanks for any advice!
|
|
|
|
|
DoEvent was never going to get you any performance benefit, and, frankly, we're all looking at you funny for even thinking so.
DoEvents stops your code and execute all the messages pending in your apps message pump. Nothing more...
What you're looking for is a code profiler. If you have an Ultimate Edition of Visual Studio, it's built in. If not, you'll have to use a third party product, none of which are free.
|
|
|
|
|
I'm probably not explaining myself clearly. If you have a long-winded loop somewhere and want to pause execution for some reason, you can't do it with a button click unless you have a DoEvents line in there so that the loop can stop long enough to process system events. By "performance", I meant that the "performance" of the Pause button improves because now it has a chance to be processed in the middle of the loop. I know that DoEvents() slows things down for exactly the reason you point out, but under the circumstances, unless there is an alternative to DoEvents(), I'm stuck.
But the other possible explanation of the problem is that somehow, no matter what loops I put my DoEvents lines in, something shuts them down so that they do not respond. Is that likely?
|
|
|
|
|
treddie wrote: you have a long-winded loop somewhere and want to pause execution for some
reason, you can't do it with a button click unless you have a DoEvents line in
there
Wrong. The correct technique is to move the long running operation to a background thread. Then you don't need DoEvents (and the headaches that come with it) and just set a flag or some other synchronization object. That way your UI isn't blocked.
|
|
|
|
|
Ah...OK. I need to think parallel these days.
And thanks for the info on code profilers. I did do a quick search and found a couple of free ones, though I don't know if they are any good, or for that matter, truly "free" (aka fully-functional, non-demo).
Thanks for the help. Much appreciated!
|
|
|
|