Click here to Skip to main content
15,888,026 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reading values from window-form to XNA Pin
larsp7775-Jan-14 22:09
larsp7775-Jan-14 22:09 
GeneralRe: Reading values from window-form to XNA Pin
Ron Beyer6-Jan-14 7:44
professionalRon Beyer6-Jan-14 7:44 
GeneralRe: Reading values from window-form to XNA Pin
larsp7776-Jan-14 8:24
larsp7776-Jan-14 8:24 
GeneralRe: Reading values from window-form to XNA Pin
larsp7773-Feb-14 22:00
larsp7773-Feb-14 22:00 
Questionhow i can auto searching devices and sending file with bluetooth using 32feet ,C#,WPf Pin
h.k_net4-Jan-14 21:32
h.k_net4-Jan-14 21:32 
AnswerRe: how i can auto searching devices and sending file with bluetooth using 32feet ,C#,WPf Pin
Kornfeld Eliyahu Peter4-Jan-14 22:29
professionalKornfeld Eliyahu Peter4-Jan-14 22:29 
QuestionCreating C# TCP listener windows Service Pin
Tobben_4-Jan-14 11:47
Tobben_4-Jan-14 11:47 
AnswerRe: Creating C# TCP listener windows Service PinPopular
Ron Beyer4-Jan-14 12:00
professionalRon Beyer4-Jan-14 12:00 
I'm assuming, since you posted the code that works and not the code you are having problems with, is that you are calling StartListening in the OnStart method of the service.

Here is a Walkthrough for creating a Windows Service[^]

Note what it says in the note under the OnStart method:

Quote:
A service application is designed to be long running. Therefore, it usually polls or monitors something in the system. The monitoring is set up in the OnStart method. However, OnStart does not actually do the monitoring. The OnStart method must return to the operating system after the service's operation has begun. It must not loop forever or block. To set up a simple polling mechanism, you can use the System.Timers.Timer component. In the OnStart method, you would set parameters on the component, and then you would set the Enabled property to true. The timer would then raise events in your code periodically, at which time your service could do its monitoring.


Your code does exactly that, it loops forever (while(true)).

So, how would you take care of that? Well you can either use the asynchronous methods instead of the synchronous ones, see Socket.BeginReceive[^] or you can create a new thread (I'd use BackgroundWorker[^]).

Remember to keep a way to stop your service, so if you use the asynchronous socket methods you will have to be able to cancel the operation, or if you use background worker you will need to have some kind of flag to exit your function.
QuestionGetting Thread Exception: while using System.Timer Class Pin
Member 99612394-Jan-14 7:16
Member 99612394-Jan-14 7:16 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Pete O'Hanlon4-Jan-14 8:15
mvePete O'Hanlon4-Jan-14 8:15 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Dave Kreskowiak4-Jan-14 10:20
mveDave Kreskowiak4-Jan-14 10:20 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Brite Varghese9-Jan-14 6:22
Brite Varghese9-Jan-14 6:22 
AnswerRe: Getting Thread Exception: while using System.Timer Class Pin
Member 99612399-Jan-14 17:47
Member 99612399-Jan-14 17:47 
QuestionC# datagridview navigator Pin
Member 78188924-Jan-14 3:58
Member 78188924-Jan-14 3:58 
AnswerRe: C# datagridview navigator Pin
Alan N4-Jan-14 4:20
Alan N4-Jan-14 4:20 
Questionabout Sign unsigned drivers Pin
delphix53-Jan-14 8:43
delphix53-Jan-14 8:43 
AnswerRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 9:05
mveDave Kreskowiak3-Jan-14 9:05 
GeneralRe: about Sign unsigned drivers Pin
delphix53-Jan-14 9:37
delphix53-Jan-14 9:37 
GeneralRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 10:29
mveDave Kreskowiak3-Jan-14 10:29 
GeneralRe: about Sign unsigned drivers Pin
delphix53-Jan-14 10:50
delphix53-Jan-14 10:50 
GeneralRe: about Sign unsigned drivers Pin
Dave Kreskowiak3-Jan-14 14:11
mveDave Kreskowiak3-Jan-14 14:11 
GeneralRe: about Sign unsigned drivers Pin
delphix54-Jan-14 2:48
delphix54-Jan-14 2:48 
Questionget the property name of custom folder Pin
Member 102635192-Jan-14 19:54
Member 102635192-Jan-14 19:54 
AnswerRe: get the property name of custom folder Pin
Eddy Vluggen3-Jan-14 6:23
professionalEddy Vluggen3-Jan-14 6:23 
QuestionDeserialize Pin
shers2-Jan-14 18:52
shers2-Jan-14 18:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.