PC Review


Reply
Thread Tools Rate Thread

2kPro + .Net + HyperThreading = Bizarre Issue?

 
 
smith
Guest
Posts: n/a
 
      7th Dec 2003
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.

NOW: Go back into the BIOS and turn HT back on. Get Back into Windows and
run the app. It Runs Fine.

Wierder still: Uninstall the application, search the machine and make sure
that it's gone. Restart the computer. Reinstall the app (Hyperthreadin
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=e...%3D10%26sa%3DN


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 Mutext 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



 
Reply With Quote
 
 
 
 
smith
Guest
Posts: n/a
 
      7th Dec 2003
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
>>> Previous



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU upgrade (hyperthreading issue) =?Utf-8?B?RGVhbg==?= Windows XP Hardware 5 10th Jan 2005 04:14 PM
Hyperthreading issue Sator Arepo Windows XP Help 8 27th Mar 2004 02:28 AM
Hyperthreading on 2kPro with .Net: Is this normal? smith Microsoft Dot NET Framework Forms 4 9th Dec 2003 04:00 PM
.Net, Hyperthreading & 2kpro: Does this issue make sense? smith Microsoft VB .NET 1 7th Dec 2003 09:39 AM
XP Hyperthreading Issue David Angelovich Windows XP Customization 2 14th Aug 2003 11:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:26 PM.