Hyperthreading on 2kPro with .Net: Is this normal?

S

smith

I was recently set to release an app that used very common single instance
code and hit the oddest issue.

After many hours of full build tests I believe that it is duplicatable.

Environment:

..Net 1.1 (v1.1.4322)
Windows 2000Pro
HyperThreading machine

Issue:

Install 2kPro on the HT box (I use an MSI-based 3.06Ghz), fully install all
Windows Updates.

Create a .Net app using the single instance code based on
Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess
..ProcessName)

Install the application on the 2k box & run it.

If the code is called in the Load even to a form you will get a "Couldn't
get process information from remote machine" exception. The exception dump
will mention not being able to get the process "ticks"

If the same code is called from a sub main rather than from a form_load then
you will get an "Unhandled Exception occurred" error.

Now, here's where it gets weird: Restart the machine and get into the BIOS.
Disable Hyperthreading and get back into Win2k. Run the app. It runs fine.
Minimize it and try to start a second instance and the first instance pops
up to the top of the order and the second instance dies. Perfect.

Now, restart and go back into the BIOS and turn HT back on. Get back into
Win2k. Run the app. It runs fine in every way.

Weirder still: Uninstall the application, search the machine and make sure
that it's gone. Restart the computer. Reinstall the app (Hyperthreading
still ON). Run the app. It runs fine!

Format the drive and fully reinstall Win2k Pro then the app. It starts all
over again.

I could understand this if the app continued to run after turning HT back on
the first time ... from my level of understanding that could be because
without HT the code could fully execute and so it got compiled for the
machine and later with HT turned back on the code was already compiled.

But why is it that after uninstalling the app fully, and just reinstalling
the app "fresh" the code runs? (And, another test app using the same code
also now runs)

XP Home and Pro have no such issue with the code with or without
Hyperthreading, it's just 2k.

I've seen a couple of mentions of the "Couldn't get process information from
remote machine" exception related to HT, but none of these few say anything
about switching HT off then on again as a fix.

Here is one of the few mentions:

http://groups.google.com/groups?hl=...%22&hl=en&lr=&ie=UTF-8&oe=UTF-8&start=10&sa=N


Can a framework or lower-level expert shed some light on why all this might
be? I'd love to hear the logic.

(I'm converting the code to use a Mutex because it appears the crux of the
matter is in the use of GetCurrentProcess.ProcessName)


Fyi: here is the code, it is fairly common:

''Declarations: (excuse the "straight style", it is for this test)

Public Const SW_NORMAL = 1
Public Const SW_MAXIMIZE = 3
Public Const SW_RESTORE = 9
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1

Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer

Declare Function ShowWindowAsync Lib "user32" (ByVal hwnd As Integer, _
ByVal nCmdShow As Integer) As Integer

Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Integer

Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, _
ByVal hWndInsertAfter As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, _
ByVal wFlags As Integer) As Integer


Sub main()
If HasPrevInstance() Then
Exit Sub
Else
Dim fMain As New Form1
fMain.ShowDialog()
End If
End Sub

Private Function PrevInstance() As Boolean
If

Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess
..ProcessName).Length > 1 Then
Return True
Else
Return False
End If
End Function

Private Function HasPrevInstance() As Boolean
If PrevInstance() = True Then
' Get all previous instances
Dim Processes() As Process
Processes =
Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess
..ProcessName)
' Activate the first instance
Dim temphwnd As Integer
Dim x As Integer
Try
For i As Integer = 0 To Processes.Length - 1
temphwnd = Processes(i).MainWindowHandle.ToInt32
x = ShowWindowAsync(temphwnd, SW_RESTORE)
'bring it to the top of the z-order
SetWindowPos(temphwnd, HWND_TOPMOST, 0, _
0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)

SetWindowPos(temphwnd, HWND_NOTOPMOST, 0, _
0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
Next

Catch ex As Exception
'Todo: Replace for release
MsgBox(ex.ToString)
End Try
Return True
Else
Return False
End If

End Function


-robert smith
kirkland, wa
 
S

smith

Oh, not "unhandled exception" but one of those fun "UnHandle-Able"
exceptions :) I'll spend the 3 hours again resetting the machine (again)
and wrap in a try...catch, might get the "remote machine process" exception
that way.

(and before you disqualify the whole: "mutex", sorry <g>)

But the question remains valid.

-s
 
S

Steve Hiner

Oh, not "unhandled exception" but one of those fun "UnHandle-Able"
exceptions :) I'll spend the 3 hours again resetting the machine (again)
and wrap in a try...catch, might get the "remote machine process" exception
that way.

(and before you disqualify the whole: "mutex", sorry <g>)

But the question remains valid.

-s

You'd save yourself a ton of testing time if you picked up Acronis
TrueImage. Then you could rebuild the OS and create an image. The next
time you needed to rebuild it you'd save yourself a couple hours or more.
 
G

Guest

TrueImage, that is imaging at runtime not boot time like ghost isnt it. If
so, its not a true image.

Or use VMWare for testing.
 
S

smith

Yeah, thanks for the tip.

But the question isn't on ghosting the test machine.

Why does Process.Getprocesses and Process.GetCurrentProcess fail on Win2k
when HyperThreading is on. Then work after you turn off Hyperthreading and
and then work every time (even on all other apps) when you turn HT back on?

Is the framework itself Jitting and it has an issue with the Process Object
with HT on Win2k, but then after you switch it off then on again the
Framework is Jitted so it will then run flawlessly?

With the economy comign back compaies are starting to buy again ... meaning
new machines, many with HT. However, as I see it the old corporate way of
OS purchases is still with us: They will buy new machines but most
companies will not jump to XP mass deployments (that will happen when
Longhorn is released ... in typical corporate fashion).

So this issue is going to be coming up a lot more often as thsoe new
machines are deployed and more .net code is deployed to them.

Thanks.

-smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top