Click here to Skip to main content
15,919,931 members
Home / Discussions / C#
   

C#

 
Questionsaperate and run for voice these two functions? Pin
umair1121-Jun-05 17:45
umair1121-Jun-05 17:45 
AnswerRe: saperate and run for voice these two functions? Pin
Christian Graus21-Jun-05 18:06
protectorChristian Graus21-Jun-05 18:06 
QuestionHow capture class function "int ISampleGrabberCB.SampleCB( double SampleTime, IMediaSample pSample )" run for voice Pin
umair1121-Jun-05 17:40
umair1121-Jun-05 17:40 
GeneralAdditional information: DragDrop registration failed. Pin
bigdave0421-Jun-05 17:28
bigdave0421-Jun-05 17:28 
GeneralRe: Additional information: DragDrop registration failed. Pin
mav.northwind21-Jun-05 20:39
mav.northwind21-Jun-05 20:39 
GeneralRe: Additional information: DragDrop registration failed. Pin
bigdave0422-Jun-05 3:02
bigdave0422-Jun-05 3:02 
GeneralRe: Additional information: DragDrop registration failed. Pin
mav.northwind22-Jun-05 20:52
mav.northwind22-Jun-05 20:52 
General.NET2 + Serial Port + Service Pin
g00fyman21-Jun-05 17:18
g00fyman21-Jun-05 17:18 
hi to all,

i have made a console app to test the new functionality of the SerialPort in the new .NET, it works fine when run as a console application, so i converted it to a service, but it doenst launch the MASTER_PROCESS that is defined.

The idea is that the service is always running, and it sends data from the serail port to the application that is the database frontend, but if the user closes the front end (for somereason) the service reopens it when the serial port receives any data.

This works as console app, but the app (notepad) wont open when running as service.

any idea pls?

<code>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO.Ports;
using System.Threading;

namespace SerialPortListener
{
partial class PortListener : ServiceBase
{
#region Private Members
/// <summary>
/// The serial port object to read the data from
/// </summary>
private SerialPort port = null;

/// <summary>
/// the thread that will run, and monitor the port for activity
/// </summary>
private Thread monitorThread = null;

/// <summary>
/// The thread state, alive or dead, alive = true.
/// </summary>
private bool alive = false;

/// <summary>
/// The proccess executable that is the master program that requires
/// the input from this port monitor
/// </summary>
private const string MASTER_PROCESS = "notepad.exe";

#endregion

#region Constructors

/// <summary>
/// Default Constructor
/// Instantiates the serial port using the default values
/// </summary>
public PortListener()
{
InitializeComponent();
this.port = new SerialPort();
this.monitorThread = new Thread(new ThreadStart(MonitorPort));
}

#endregion

#region Thread Members

/// <summary>
/// Starts the thread to listen to the serial port
/// </summary>
protected override void OnStart(string[] args)
{
// start the thread
this.monitorThread.Start();
}

/// <summary>
/// Stops the thread that is listening to the serial port, using Thread.Abort()
/// </summary>
protected override void OnStop()
{
if (this.monitorThread.IsAlive)
{
this.alive = false;
this.monitorThread.Abort();
}
}


/// <summary>
/// Thread method that will monitor the port and handle the data from the port
/// </summary>
private void MonitorPort()
{
this.alive = true;

// loop while the bool is set true, if set false the thread will terminate
while (this.alive)
{
try
{
Thread.Sleep(100);
this.port.Open();

// check if master program is running
if (!IsRunningProcess(MASTER_PROCESS))
{
this.StartMasterProcess();
}
String data = this.port.ReadLine();
this.port.Close();
}
catch (Exception e)
{
Console.WriteLine("EXCEPTION: " + e.Message);
}
}

try
{
// kill the thread
this.monitorThread.Abort();
}
catch (Exception e)
{ }
}

#endregion

#region Private Helpers

/// <summary>
///
/// </summary>
/// <param name="processName"></param>
/// <returns></returns>
private bool IsRunningProcess(String processName)
{
Process[] p = Process.GetProcessesByName(processName);
if (p.Length == 0)
{
return false;
}
return true;
}


private void StartMasterProcess()
{
Process p = new Process();
p.StartInfo.FileName = MASTER_PROCESS;
p.Start();
}

#endregion

}
}

</code>

Kind regards,
g00fy
GeneralRe: .NET2 + Serial Port + Service Pin
g00fyman21-Jun-05 17:38
g00fyman21-Jun-05 17:38 
GeneralRe: .NET2 + Serial Port + Service Pin
g00fyman21-Jun-05 18:07
g00fyman21-Jun-05 18:07 
GeneralRe: .NET2 + Serial Port + Service Pin
Dave Kreskowiak22-Jun-05 5:00
mveDave Kreskowiak22-Jun-05 5:00 
GeneralRe: .NET2 + Serial Port + Service Pin
g00fyman22-Jun-05 12:04
g00fyman22-Jun-05 12:04 
GeneralRe: .NET2 + Serial Port + Service Pin
g00fyman22-Jun-05 12:23
g00fyman22-Jun-05 12:23 
GeneralA strange problem .......Help me please...I can't stand any more... Pin
Khanh Duy21-Jun-05 16:50
Khanh Duy21-Jun-05 16:50 
Generala gui refresh question Pin
cchere21-Jun-05 16:29
cchere21-Jun-05 16:29 
GeneralRe: a gui refresh question Pin
mav.northwind21-Jun-05 20:14
mav.northwind21-Jun-05 20:14 
GeneralRe: a gui refresh question Pin
S. Senthil Kumar21-Jun-05 20:46
S. Senthil Kumar21-Jun-05 20:46 
GeneralRegular Expression Code for Syntax Highlighting Pin
C_Simpkins21-Jun-05 14:14
C_Simpkins21-Jun-05 14:14 
GeneralRe: Regular Expression Code for Syntax Highlighting Pin
mav.northwind21-Jun-05 20:32
mav.northwind21-Jun-05 20:32 
GeneralRe: Regular Expression Code for Syntax Highlighting Pin
C_Simpkins21-Jun-05 20:40
C_Simpkins21-Jun-05 20:40 
Questionit make a dll but how? Pin
Sasuko21-Jun-05 13:42
Sasuko21-Jun-05 13:42 
AnswerRe: it make a dll but how? Pin
Christian Graus21-Jun-05 13:54
protectorChristian Graus21-Jun-05 13:54 
Generalchanging pixels color Pin
sami_bio@yahoo.com21-Jun-05 11:40
sami_bio@yahoo.com21-Jun-05 11:40 
GeneralRe: changing pixels color Pin
Christian Graus21-Jun-05 13:38
protectorChristian Graus21-Jun-05 13:38 
GeneralRe: changing pixels color Pin
sami_bio@yahoo.com21-Jun-05 18:33
sami_bio@yahoo.com21-Jun-05 18:33 

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.