Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc
Threads  ApartmentState etc Threads  ApartmentState etc
Threads  ApartmentState etc
Go Back  Xtreme Visual Basic Talk > > > Threads ApartmentState etc


Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2015, 05:13 AM
Roger-U Roger-U is offline
Centurion
 
Join Date: Apr 2008
Location: Surrey, UK
Posts: 111
Default Threads ApartmentState etc


I have quite a large program (the zip has a very stripped down extract!) that runs on all Windows platforms.. unitl recently someone tried it on Windows 8.1 running with a Single Core processor. And then one of the threads just hangs

Code:
    With New System.Threading.Thread(AddressOf loadbits)
      .SetApartmentState(System.Threading.ApartmentState.STA)
      .Start()
      Do
        '  System.Windows.Forms.Application.DoEvents()  
        System.Threading.Thread.Sleep(10)
      Loop While .IsAlive

    End With
actually the loadbits sub itself times out.
If I disable the SetApartmentState statement it works
or if I add the DoEvents statement it works

This bug only happens on the Single Core processor PC running Windows 8.1, so if anyone out there happens to have such a system I'd love to know if it hangs for you too.

The loadbits actually makes an http request and the request is being sent as I can see it on my server, but the Webclient object does not receive the response.


And on a related note: does anyone know of a decent document on how/when to use SetApartmentState. Yes I have read the MSDN... but it really doesn't explain, in terms a VB programmer can understand, how it should be used.



Where has everyone gone? This site is very quiet of late

Roger
Attached Files
File Type: zip ThreadTest.ZIP (196.8 KB, 1 views)
Reply With Quote
  #2  
Old 02-03-2015, 03:50 PM
Cerian Knight's Avatar
Cerian KnightThreads  ApartmentState etc Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

Not sure if it is relevant, but historically single core Windows OSes use a different timer granularity than multi-core. With that thought, I find this:
Quote:
A single CPU/core system simply cannot cope with multiple timed events setup to signal within the same interrupt period.
... here: http://www.windowstimestamp.com/description

Perhaps try Sleep(0) to see the effect, if avoiding the DoEvents is your end goal.

I'm curious about which CPU model has only 1 core? Using said processor would be less than desirable under Win 8.1, though probably better than the same under Win 7.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #3  
Old 02-03-2015, 05:17 PM
PlausiblyDamp's Avatar
PlausiblyDampThreads  ApartmentState etc PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

The ApartmentState is only relevant when dealing with COM objects, so if you aren't then it makes no difference anyway and you are probably best ignoring it.

Generally speaking if you are interacting with a COM object that isn't thread safe you should use STA (typical example would be a COM component that is part of the UI), otherwise MTA is normally the best option.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #4  
Old 02-04-2015, 01:51 AM
Roger-U Roger-U is offline
Centurion
 
Join Date: Apr 2008
Location: Surrey, UK
Posts: 111
Default

Thankyou for your insights. "if avoiding the DoEvents is your end goal" -- the DoEvents isn't an issue; I really just wanted it to work on this old computer - and really just want to confirm that the issue is related to trying to run W8 on a single core processor, rather than something I was doing wrong.

The code snippet fails ONLY when used as shown: with STA, without DoEvents
without STA it works with or without the DoEvents

The loadbits routine uses System.Net.WebClient.

And, since the first post, another little quirk showed itself ...

... so I think a single core cpu probably is being asked to do just too much in W8 -though it was running W7 before.

This particular system is in a South American country - maybe his real mistake was actually using a legitimate version of Windows


Processor:
Number of cores 1 (max 1)
Name AMD Sempron 140
Codename Sargas
Specification AMD Sempron(tm) 140 Processor
Package Socket AM3 (938)
CPUID F.6.2
Extended CPUID 10.6
Reply With Quote
  #5  
Old 02-04-2015, 02:56 AM
PlausiblyDamp's Avatar
PlausiblyDampThreads  ApartmentState etc PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Could be a problem with WebClient, perhaps it is doing some interop behind the scenes and that is causing the problem.

Have you tried using the newer HttpClient (https://msdn.microsoft.com/en-us/lib...vs.118%29.aspx) class instead, that might not have the same problem. Plus the HttpClient uses the newer Async functionality so you won't need to mess with threads directly either.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #6  
Old 02-04-2015, 07:02 AM
Cerian Knight's Avatar
Cerian KnightThreads  ApartmentState etc Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

Trivia: On some motherboards the second core on a Sempron 140 can be unlocked and then often works well (since yields were good and this bin was mainly just for marketing).
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc Threads  ApartmentState etc
Threads  ApartmentState etc
Threads  ApartmentState etc
 
Threads  ApartmentState etc
Threads  ApartmentState etc
 
-->