473,395 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Threading on FW1.1

Hello everybody,

I'm quite new to .NET FW programming, and I started just few months ago, on
FW2.0, knowing actually _nothing_ about FW1.1, so my question may sound
silly...

Anyway, what I need to know is: does Threading on FW1.1 behave exactly the
same than on FW2.0?

In particular my problem is this: I wrote a windows service and compiled it
on FW2.0 and now I had to performe a "backporting" to FW1.1, because of
some customers' request. My service is quite simple: it implements a server
listening for incoming connections on a specified port. In order to avoid
a timeout exception starting the server (that occours after 30 seconds, if
I'm right...) I've overriden the "OnStart()" method from the "ServiceBase"
class, and set inside it (I hope it's enough self-exlaining):

MyServer server = new MyServer();
protected void OnStart(String[] args) {

Thread t = new Thread(new ThreadStart(server.StartListening));
t.Start();
}

so that the OnStart() method returns in a little time.
The version compiled for the FW2.0 works wihtout any problem but with the
one compiled for FW1.1 I get a timeout and cannot start the service.
Can anyone help me?

Thanks in advance.
Kind regards,
Giulio - Italia

--
On Air: Metallica - Shortest Straw
--
Jun 13 '06 #1
5 1240
Giulio,
Set the t thread's IsBackground property to true.
You may need to post more code. In your StartListening method, How do you
track that server is supposed to keep running? Do you have a "while
(isRunning) " type of boolean that gets set to false in the StopListening
method?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Giulio Petrucci" wrote:
Hello everybody,

I'm quite new to .NET FW programming, and I started just few months ago, on
FW2.0, knowing actually _nothing_ about FW1.1, so my question may sound
silly...

Anyway, what I need to know is: does Threading on FW1.1 behave exactly the
same than on FW2.0?

In particular my problem is this: I wrote a windows service and compiled it
on FW2.0 and now I had to performe a "backporting" to FW1.1, because of
some customers' request. My service is quite simple: it implements a server
listening for incoming connections on a specified port. In order to avoid
a timeout exception starting the server (that occours after 30 seconds, if
I'm right...) I've overriden the "OnStart()" method from the "ServiceBase"
class, and set inside it (I hope it's enough self-exlaining):

MyServer server = new MyServer();
protected void OnStart(String[] args) {

Thread t = new Thread(new ThreadStart(server.StartListening));
t.Start();
}

so that the OnStart() method returns in a little time.
The version compiled for the FW2.0 works wihtout any problem but with the
one compiled for FW1.1 I get a timeout and cannot start the service.
Can anyone help me?

Thanks in advance.
Kind regards,
Giulio - Italia

--
On Air: Metallica - Shortest Straw
--

Jun 13 '06 #2


"Giulio Petrucci" <gi*************@RIMUOVIspeechvillage.com> wrote in
message news:u6**************@TK2MSFTNGP05.phx.gbl...
| Hello everybody,
|
| I'm quite new to .NET FW programming, and I started just few months ago,
on
| FW2.0, knowing actually _nothing_ about FW1.1, so my question may sound
| silly...
|
| Anyway, what I need to know is: does Threading on FW1.1 behave exactly the
| same than on FW2.0?
|
| In particular my problem is this: I wrote a windows service and compiled
it
| on FW2.0 and now I had to performe a "backporting" to FW1.1, because of
| some customers' request. My service is quite simple: it implements a
server
| listening for incoming connections on a specified port. In order to avoid
| a timeout exception starting the server (that occours after 30 seconds, if
| I'm right...) I've overriden the "OnStart()" method from the "ServiceBase"
| class, and set inside it (I hope it's enough self-exlaining):
|
| MyServer server = new MyServer();
| protected void OnStart(String[] args) {
|
| Thread t = new Thread(new ThreadStart(server.StartListening));
| t.Start();
| }
|
| so that the OnStart() method returns in a little time.
| The version compiled for the FW2.0 works wihtout any problem but with the
| one compiled for FW1.1 I get a timeout and cannot start the service.
| Can anyone help me?
|

What's the exact error message you get?
Are you sure the thread has started (succesfully), that is, that your
'server.StartListening' has been entered?
Did you try to run this in the debugger?

Willy.

Jun 13 '06 #3
Hi ,

I think that the code is correct.

Maybe you do not need a MyServer class, and just use a method of the
instance.

You shoudl not be getting any timeout at all

do you know fi thyou get any message in the Application log?
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Giulio Petrucci" <gi*************@RIMUOVIspeechvillage.com> wrote in
message news:u6**************@TK2MSFTNGP05.phx.gbl...
Hello everybody,

I'm quite new to .NET FW programming, and I started just few months ago,
on FW2.0, knowing actually _nothing_ about FW1.1, so my question may sound
silly...

Anyway, what I need to know is: does Threading on FW1.1 behave exactly the
same than on FW2.0?

In particular my problem is this: I wrote a windows service and compiled
it on FW2.0 and now I had to performe a "backporting" to FW1.1, because of
some customers' request. My service is quite simple: it implements a
server listening for incoming connections on a specified port. In order to
avoid a timeout exception starting the server (that occours after 30
seconds, if I'm right...) I've overriden the "OnStart()" method from the
"ServiceBase" class, and set inside it (I hope it's enough
self-exlaining):

MyServer server = new MyServer();
protected void OnStart(String[] args) {

Thread t = new Thread(new ThreadStart(server.StartListening));
t.Start();
}

so that the OnStart() method returns in a little time.
The version compiled for the FW2.0 works wihtout any problem but with the
one compiled for FW1.1 I get a timeout and cannot start the service.
Can anyone help me?

Thanks in advance.
Kind regards,
Giulio - Italia

--
On Air: Metallica - Shortest Straw
--

Jun 13 '06 #4
Hi Peter,
Hi Willy,
Hi Ignacio,
Hi everybody

First of all, thanks for your replies, I'll answer here, "all in one" :-)

Peter Bromberg [C# MVP] ha scritto:
Set the t thread's IsBackground property to true.
Ok, I'll try...
You may need to post more code. In your StartListening method, How do you
track that server is supposed to keep running? Do you have a "while
(isRunning) " type of boolean that gets set to false in the StopListening
method?


class MyService : ServiceBase {

MyServer server;

MyService() {
//new instance of MyServer class;
server = new MyServer();
}

protected void OnStart(String[] args) {
Thread t = new Thread(new ThreadStart(server.StartLisrening));
t.Start();

}
}

class MyServer
{
private ManualResetEvent allDone = new ManualResetEvent(false);
public void StartListening() {
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, port);
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
try {
listener.Bind(localEndPoint);
listener.Listen(100);
while(true) {
acceptDone.Reset();
listener.BeginAccept(new
AsyncCallback(AcceptCallback),listener);
//using dbgviewer and setting dozens of tracelines //I see that the
execution arrives 'till here...
**acceptDone.WaitOne();**
}
}
catch (Exception e) {
//...some code...
}
}
private void AcceptCallback(IAsyncResult ar) { ... }
}
Ok, that's the "core" code. This, compiled on the FW2.0 works greatly. I
set in the code lots of tracelines, writing on the DefaultTraceListener and
I could realize that the server starts "regulary" and the executions gets
the line marked as **...** here above. Now I'll try to set the thread
spawned in the OnStart service method as a background one and let you know.

Thanks again,
Giulio - Italia

--
On Air: YES - The revealing Science of God
--

Jun 14 '06 #5
Hi Peter,
Hi everybody,

Peter Bromberg [C# MVP] ha scritto:
Giulio,
Set the t thread's IsBackground property to true.


I've just tested it... nothing changed :-(

Thanks,
Giulio - Italia
Jun 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.