Tewl
xTeam
C# & VB Developer
Posts: 495
|
Post by Tewl on Jun 1, 2003 10:54:36 GMT -5
I keep seeing [STAThread] above my main in my C# applications, what is this for?
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 1, 2003 13:29:21 GMT -5
You mean in your source code file? cant you just delete it?
|
|
z00ey
New Member
return is the movement of sense..
Posts: 2,309
|
Post by z00ey on Jun 1, 2003 13:40:45 GMT -5
i m not into C# ..but it looks like a basic stream/library that is included.. ..like <iostream> eg for basic in and output stuff in c++.. ..maybe it stands for [STAndardThread], but just a guess.
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 1, 2003 14:43:47 GMT -5
posts from somewhere br] ******************** What's the best way to launch the user's preferred browser from a C# application? For example, one might want a button labelled "CNN" in an application, so that when the button is clicked, the user's preferred browser (not necessarily IE) comes up at cnn.com. After searching through the registry and the .NET documentation, I figured I'd ask here. Andrew ********************* Hi Andrew, I'd use the System.Diagnostics.Process class. Instead of specifying an application, just give the URL and let the user's default settings take over for that file type. Kind of like this: System.Diagnostics.Process.Start("http://www.cnn.com"); Joe ********************* Something like that would be great. The particular line you gave doesn't work, apparently because the argument isn't a file name. Does that work on your machine? If so, maybe we are using different versions of .NET. Andrew ******************* Yes, this works fine on my machine. I'm using .NET v1.0 w/SP2 and don't have any other version installed. I just figured it was an OS thing that made the determination - perhaps that isn't so. Here's the code I ran: using System; namespace TestNamespace { class Test { [STAThread] static void Main() { System.Diagnostics.Process.Start("http://www.cnn.com"); Console.ReadLine(); } } } Joe ************ Thanks. That worked fine on my machine too. The reason it was not working in my application is that the application didn't have [STAThread]. (See the MSDN documentation for System.Diagnostics.Process.Start for some information about interactions between the apartment model and Process.Start.) I don't understand apartment models very well yet; I'm not sure whether to use STAThread in my application. I wonder whether using STAThread might make things slow. I guess that even if I don't STAThread in my application, I could create a separate little executable that does use STAThread, and invoke the browser from there. Or maybe there is something more elegant. *********************** Anything that uses ActiveX, VB COM objects, or Windows Forms and COM requires a single threaded apartment, which is what the [STAThread] attribute guarantees. I thing that adding[STAThread] by default is generally good to do. Although I do recall reading a couple times where people ran into problems trying to use MTA components, when their application was defaulting to STA because of the [STAThread] attribute. My impression is that MTA components are an exception that you won't see much unless you are doing direct COM Interop with MTA components. Then again, I know just enough COM to be dangerous. Joe ******************** Alright, I am going to use STAThread and see what happens. Andrew ********************* i dunno if that helps, but it talks about STAThread and i thought you could make sense of it Tewl.
|
|
Tewl
xTeam
C# & VB Developer
Posts: 495
|
Post by Tewl on Jun 1, 2003 14:50:08 GMT -5
i saw that post earlier but its still kind of vege
|
|
Trad
New Member
Posts: 1,122
|
Post by Trad on Jun 1, 2003 14:52:34 GMT -5
how about looking up System.Diagnostics.Process.Start in MSDN? i think he is referring to STAThread, cos he said it didnt work without it, or even search MSDN for [STAThread], that will almost deffinatly give you an answer.
|
|
FooK
New Member
Posts: 44
|
Post by FooK on Jun 1, 2003 15:10:34 GMT -5
.Net as a concept had potential to realy change the face of High Level Lang , but Microsoft Hashed it up sadly C# is a worthless peice of junk, i can code the same applications in Standard C or Pascal and even assembly if you know what your doing- Frankly its a joke, you can get the .net Compilers for free from MS's site , there only command line but there are IDE's out there that almost fully support the features of .net so why go out and spend a feck load on the MS IDE becuase realy thats all your paying for, seeing as the command line tools the IDE uses are FREE! .Net may be around a while but it certianly wont have the same effect C++ or JAVA had , its simply a new wrapper on very old concepts, on saying that the one good thing thats come from .net is that the Libarys are crossable between .net siblings , but thats the only good thing ive seen so far! but always good to see people teach them self new stuff Keep it up Tewl ;D dont let my tone put you off, im just a Low Level junkie that refuses to give up on my trusty assembler ( yup it was a rant!!!!!!!!!!!!! >_<
|
|
Tewl
xTeam
C# & VB Developer
Posts: 495
|
Post by Tewl on Jun 1, 2003 16:24:08 GMT -5
lol well im a vb programmer always will be i just wanted to play around a bit with C# since the syntax is a lot like vb .net
|
|