|
Hi,
the thread that executes your do-loop will burn CPU cycles at full throttle. So one of your two cores is out of business, waiting for the process to terminate (which gets delayed by the fact that your system is now limping on one core).
The right way to do this is:
- either include a Thread.Sleep(100) or so inside the while loop, so in spins only 10 times per second;
- or better yet, use something smarter, more event-driven; in this case replace the whole do-loop by a simple varProcess.WaitForExit
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
It was so simple I almost didn't believe it.
Thanks for the quick reply. I already modified the code using .WaitForExit and my application is working as expected, without the high CPU utilization.
|
|
|
|
|
You're welcome.
And don't do this ever again! A loop that waits for something to happen should either relinquish the CPU (that's what Sleep does), or perform a blocking call (such as WaitForSomething).
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
I have a class which is supposed to simulate part of a piece of hardware. When the object is created, the constructor is given a reference to the underlying CPU-control object (an object of the class has no meaning without such a base object). The class needs a substantial number of "WithEvents" other objects which need to attach themselves to the underlying CPU control object. For example, "Dim MotorEnable as New IoBit(baseCPU, 4, 6)" will cause any writes to MotorEnable.pin to be visible on bit 6 of port 4 in the base CPU, and will cause any CPU writes to bit 6 of port 4 to trigger a "MotorEnable.PinChanged" event in the hardware-simulation object.
The "Dim XX as New YY(params)" format of declaration is much more appealing than having a separate declaration and initialization. Unfortunately, even though the identity of the new master CPU object is known before all the "Dim XX as New YY()" statements start firing (they fire in response to calling New() with the master object as one of its parameters), as far as I can tell it only exists as a local variable which is not accessible to them.
Is there any clean way to handle such constructs? Possible approaches:
-1- Have the code for the piece of hardware Inherit the base CPU object, and create the new hardware object instead of the base CPU. That would work, but only for the case where there was only one hardware class trying to extend the CPU.
-2- Have the code for the sub-feature objects accept a pointer to an iWillSupplyBase object, which will fire an event that will supply the real base CPU object. If the hardware simulation object implements iWillSupplyBase, it can fire the event within its New() procedure; the sub-feature objects can then attach themselves to the base object at that time.
-3- Use a shared factory method which sets a ThreadStatic reference to the base CPU object and then calls the constructor. The "Dim As New" statements could then pass the ThreadStatic reference to the object constructors. This would probably work fine, but it seems really icky.
-4- Have the simulation object create its own set of port handlers attached to the base CPU, and attach the port pins to those rather than the base CPU. That might be workable, but it seems rather icky, and would add a couple more levels of indirection to all I/O operations.
-5- Give up on the Dim As New syntax, even though it makes much of the code nicer and easier to read.
Is there any other brilliant approach I'm missing?
|
|
|
|
|
how I can make the installation steps for windows application (vb.net) project to enable me to install my project to any computer without install vb.net?
|
|
|
|
|
The .net framework is required to run applications written with a .net language....
...what?
|
|
|
|
|
You don't have to install VB.NET. You DO have to install the .NET Framework version that your app was written against.
|
|
|
|
|
Hello Everyone,
I hope you can help me out with this. If it is not posted to the correct forum could you point me in the proper direction? Onto the question:
I have written an application in excel that calculates the time it takes a train travel between two points accounting for permanent speed zones and temporary speed restrictions. The application works perfectly except for one (actually two) thing(s), consider the following:
Workbook 1 has a set of data for analysis, when I run the application the data is analyzed perfectly. Now, workbook 2 has a different set of data for analysis (for example speeds in place as forecasted 3 months out), when workbook 2 is analyzed it analyzes perfectly. HOWEVER, when I have both workbooks open at the same time to compare it seems like each gets confused as to what set of data should be analyzed.
The workbooks, well, application is set up as follows:
1. Data stored in Access DB
2. Workbooks pull appropriate data from DB and insert it into the appropriate tabs
3. Workbooks then process the data across more tabs
4. Funtions work from those tabs to present the analysis on a summary tab
So, each workbook has it own sheets holding the data in such a manner to allow for the analysis.
However, it seems like when both workbooks are open the first reads the data from the tabs of the second. I think the problem is that I am implicitly referencing tabs in the function I have written, and not explicitly referencing which tab I want to process. Here is a snippet of the offending code:
Function CalcSubRT(sArg As String, cArg As String, tArg As String, tLen As Integer) As Double
Application.Volatile
Dim c As Integer, t As Integer, i As Integer
Dim lm As Double, hm As Double, d As Double, rt As Double
i = 2
c = GetC(cArg)
t = GetT(tArg)
rt = 0
Do While Worksheets(sArg).Cells(i, c) <> ""
lm = Worksheets(sArg).Cells(i, c + 1)
hm = Worksheets(sArg).Cells(i, c + 2)
d = (hm - lm) * 5280
If Worksheets(sArg).Cells(i, c) <> 1 Then
If Worksheets(sArg).Cells(i - 1, c + t) < Worksheets(sArg).Cells(i, c + t) Then
d = d - (tLen / 2)
Else
If Worksheets(sArg).Cells(i - 1, c + t) > Worksheets(sArg).Cells(i, c + t) Then
d = d + tLen
End If
End If
End If
If Worksheets(sArg).Cells(i + 1, c) <> "" Then
If Worksheets(sArg).Cells(i + 1, c + t) > Worksheets(sArg).Cells(i, c + t) Then
d = d - (tLen / 2)
Else
If Worksheets(sArg).Cells(i + 1, c + t) < Worksheets(sArg).Cells(i, c + t) Then
d = d + tLen
End If
End If
End If
d = d / 5280
rt = rt + (d / Worksheets(sArg).Cells(i, c + t))
i = i + 1
Loop
CalcSubRT = rt
End Function
I think the problem lies in where I state Worksheets().Cells().
Any help would be much appreciated.
|
|
|
|
|
You'd probably have a better bet with a forum that deal with Excel specifically.
But, I would venture to guess that your not specifying the absolute workbook object to use when referencing cells, so it MIGHT be using ActiveWorkbook, or making some other assumption about which workbook it's actually dealing with.
Just a shot in the dark. I don't normally write much code for Excel.
|
|
|
|
|
I created a control array (for slots)
Private Sub createlblSlotArray()
Dim i As Short
ReDim lblSlot(3)
For i = 1 To 3
lblSlot(i) = New System.Windows.Forms.Label
With lblSlot(i)
.Tag = i
.BackColor = System.Drawing.Color.Blue
.BorderStyle = BorderStyle.Fixed3D
AddHandler .MouseUp, AddressOf Me.Label1_MouseUp
End With
Next
Me.Controls.AddRange(lblSlot)
lblSlot(1).Location = New System.Drawing.Point(50, 50)
lblSlot(2).Location = New System.Drawing.Point(100, 70)
lblSlot(3).Location = New System.Drawing.Point(100, 90)
End Sub
I have an event to handle it
Private Sub Label1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If e.Button = MouseButtons.Right Then
ContextMenu1.Show(sender, New Point(e.X, e.Y))
End If
End Sub
All is perfect with the world, except one little thing. When I click on the form itself, I get the popup. Why do I get it on the form, how can I prevent this?
No-e
|
|
|
|
|
Dunno, I copied your code into a test project and the ContextMenu is displayed when right clicking on the labels (I had to DirectCast(sender, Control) though). The menu is not displayed when clicking on the form.
There isn't a need to create a new question everytime for something you've already asked. You could have replied on your previous question since it is the same.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
huh?
Same question? Things change from vb6 to .net. I am trying to understand how things work. I tend to be a quick learner, but am just asking for help or a tip where to look when I do not understand something. This project was dropped in my lap and I have many other things to deal with.
last Q was why my mouse position was in an unexpected location. Thanks to Henry Minute, it saved me some time, perfect! that is all I ask, point me in a direction
should I not bother here? Am I asking unfair questions? Should I go away?
No-e
BTW, I found a way to address the problem. no thanks to your response. I am disappointed with your response, I thought CP members were a little more considerate. I am not a student asking you to do my homework.
|
|
|
|
|
Hmm, I recall a previous post related to a context menu and where it appeared the day before (and was appearing unexpectedly). Dunno, kinda seemed related to me.
Regardless, I'm sorry that I took time out of my day to create a test project with your code to find a possible error.
No need to apologize. I'll restrain from replying to any of your future posts.
Cheers!
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
I think it's better write this code:
Private Sub createlblSlotArray()
Dim i As Short
ReDim lblSlot(3)
For i = 1 To 3
lblSlot(i) = New System.Windows.Forms.Label
With lblSlot(i)
.Tag = i
.BackColor = System.Drawing.Color.Blue
.BorderStyle = BorderStyle.Fixed3D
.ContextMenu=ContexMenu1
End With
Next
Me.Controls.AddRange(lblSlot)
lblSlot(1).Location = New System.Drawing.Point(50, 50)
lblSlot(2).Location = New System.Drawing.Point(100, 70)
lblSlot(3).Location = New System.Drawing.Point(100, 90)
End Sub
bah10z
|
|
|
|
|
hi,
im new in vb.net
i did print using printdocument.
its perfectly working..
only drawback is nothing show in second page.
event also not occur.
plz help me...
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
|
|
|
|
|
Hi,
Not sure I understood you correctly.
Anyway, in .NET you get one PrintPage event per page.
You have to set PrintPageEventArgs.HasMorePages true in order to get an event for the next page.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
ya i have put this event argument.
but page document page is counting morethan 100 pages...
i cant understand.. what s going on..
plz help me....
Yours,
KaNNaN
-----------------------------------------------------------------
"Success is When Ur Signature Becomes An Autograph"
Mail To : foreverkans@gmail.com
|
|
|
|
|
Hello.
I am currently working on a project to extract data from a PDF document into structured database tables. I have solved the problem of extracti9g the text from a pdf into a text box in vb6 form by using a readymade dll component that I referenced in my program.
Now my problem is, how to extract only certain pieces of data from the text based on some keywords that appear in the text. for example in the pdf document:
Existing Chemical Substance ID: 50–00–0
CAS No. 50–00–0
EINECS Name formaldehyde
EINECS No. 200–001–8
Molecular Formula CH2O
I need to extract "50-00-0" that appears after the keyword "CAS No.", then
the text "formaldehyde" that appears after the keyword "EINECS Name" and "200-001-8" that comes after "EINECS No.". I have database table which contain these keywords as field names. What I want is the table to look like this:
Sno CAS No. EINECS Name EINECS No.
1 50–00–0 formaldehyde 200–001–8
I would really appreciate it if someone could point me towards the string manipulation functions that I would need to use i order to do this.
Also How to get count of a keyword if it appears multiple times between two other keywords.
Thanks and Regards,
Kumar
|
|
|
|
|
|
Dear Dave,
Thanks a lot for the suggestion.
I found just the perfect piece of code.
<br />
Public Function Extract(ByVal TextIN As String, Optional StartTag As String = " ", Optional ByVal EndTag As String = " ", Optional ByVal CheckCase As Boolean) As String<br />
On Error GoTo LocalError<br />
' Extracts Text from string using start and end "tags"<br />
'NB: If EndTag is ommitted the entire string from:<br />
' StartTag to EndOfString is returned...<br />
Dim lArray As Variant<br />
Extract = ""<br />
lArray = Split(TextIN, StartTag)<br />
If IsArray(lArray) Then<br />
Extract = lArray(1)<br />
lArray = Split(Extract, EndTag)<br />
If IsArray(lArray) Then<br />
Extract = lArray(0)<br />
Else<br />
Extract = ""<br />
End If<br />
End If<br />
Exit Function<br />
LocalError:<br />
Extract = ""<br />
End Function<br />
It works beautifully. Now, All I need to do is put all the keywords into a database and do a recursive search using those fields dynamically at runtime.
Thanks a million for your help.
Best Regards,
Kumar
|
|
|
|
|
kshincsk wrote: I found just the perfect piece of code.
Great. Yet another Copy'N'Paste programmer...
|
|
|
|
|
Hi,
i got a DSP function for a media player here. The problem is that it was made for VB 6 and uses "CopyMemory".
I read the article on "CopyMemory in .Net" here but the result i got isn't working :-S
This is the original code:
Public Sub SBVocalCut32(ByVal handle As Long, ByVal channel As Long, ByVal buffer As Long, ByVal length As Long, ByVal user As Long)<br />
Dim SBVocCut32Buf() As Single, SBVocCut32CSample As Long<br />
Dim SBVocCut32DM As Single<br />
ReDim SBVocCut32Buf(length / 2) As Single<br />
<br />
Call CopyMemory(SBVocCut32Buf(0), ByVal buffer, length)<br />
<br />
For SBVocCut32CSample = 0 To length / 2 - 1 Step 2<br />
SBVocCut32DM = ((0 - SBVocCut32Buf(SBVocCut32CSample)) + SBVocCut32Buf(SBVocCut32CSample + 1)) / 2<br />
SBVocCut32Buf(SBVocCut32CSample) = SBVocCut32DM<br />
SBVocCut32Buf(SBVocCut32CSample + 1) = SBVocCut32DM<br />
Next SBVocCut32CSample<br />
<br />
<br />
Call CopyMemory(ByVal buffer, SBVocCut32Buf(0), length)<br />
End Sub
Could anyone be so kind and help me out with the copymemory lines in here?
Thx!
|
|
|
|
|
Knight_Rider wrote: CopyMemory in .Net
which article, there are several here on CP.
Knight_Rider wrote: isn't working
that is really informative. Build problems? run-time problems? exceptions? what?
CopyMemory[^] seems to just copy some data in memory, something a simple for loop could do easily, provided source and destination do not overlap (if they do, the order must depend on the relative position).
Write your own copy loop and get done with it!
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi,
Equivalent of CopyMemory in .NET[^] This is the article i'm refering to
Yeah i tried that with the loop already:
For i As Integer = 0 To length / 2 - 1<br />
SBVocCut32Buf(i) = buffer.ToString(i)<br />
Next
and
<br />
For i As Integer = 0 To SBVocCut32Buf.Length - 1<br />
buffer += SBVocCut32Buf(i)<br />
Next<br />
But it doesn't work either because the song doesn't sound (-> Bass.NET Audio library) different after activating this function..
Thanks anyway!
BTW: There is an AccessViolationException when i use copymemory in .NET!
|
|
|
|
|
Hi,
that article is voted rather low, there is at least one that looks better.
Both these for loops stink; there is no ToString() and no += involved, just COPY data.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|