Click here to Skip to main content
15,906,106 members
Home / Discussions / C#
   

C#

 
QuestionDelegate awkwardness---is there a better way? Pin
Domenic Denicola12-Oct-07 16:35
Domenic Denicola12-Oct-07 16:35 
AnswerRe: Delegate awkwardness---is there a better way? Pin
PIEBALDconsult12-Oct-07 16:43
mvePIEBALDconsult12-Oct-07 16:43 
AnswerRe: Delegate awkwardness---is there a better way? Pin
S. Senthil Kumar12-Oct-07 22:45
S. Senthil Kumar12-Oct-07 22:45 
GeneralRe: Delegate awkwardness---is there a better way? Pin
Domenic Denicola13-Oct-07 7:28
Domenic Denicola13-Oct-07 7:28 
QuestionExtracting files from inside a file archive Pin
Luminare12-Oct-07 16:16
Luminare12-Oct-07 16:16 
AnswerRe: Extracting files from inside a file archive Pin
Roger CS13-Oct-07 11:52
Roger CS13-Oct-07 11:52 
GeneralRe: Extracting files from inside a file archive Pin
Luminare14-Oct-07 10:48
Luminare14-Oct-07 10:48 
QuestionSystem.IO.Exception Pin
solutionsville12-Oct-07 13:53
solutionsville12-Oct-07 13:53 
I am building a Windows Service and keep getting a System.IO.Exception {"The process cannot access the file 'J:\\Projects\\RTalarms_20071008.txt' because it is being used by another process."}.

Nothing has the file open. It is just sitting in the directory. The Bolded area is where the error occurs.
Any Idea why?

Confused | :confused:

This the 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;
using System.Data.SqlClient;

namespace MCPAlarmMonitor
{
public partial class MCPAlarmMonitorService : ServiceBase
{
public MCPAlarmMonitorService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
fileSystemWatcher1.EnableRaisingEvents = true;
}

protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop your service.
fileSystemWatcher1.EnableRaisingEvents = false;
}

private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
using (StreamReader reader = new StreamReader(e.FullPath)) {
string text = reader.ReadLine();

while (text != null)
{
text = text.TrimEnd(' ');

string[] tokens = text.Split(',');

InsertRecord(tokens);

text = reader.ReadLine();
}
}
}

private void InsertRecord(string[] tokens)
{
using (SqlConnection connection = new SqlConnection("server=localhost;database=MCPAlarms;integrated security=true"))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "insert into AlarmsList values(@DateTime,@Address,@Location,@State,@notused1,@notused2,@AlarmMessage)";

for (int i = 0; i < 8; i++)
{
string parameterName = string.Format("@Column{0}", i + 1);
string parameterValue = tokens.Length > i ? tokens[i] : string.Empty;
command.Parameters.AddWithValue(parameterName, parameterValue);
}

connection.Open();
command.ExecuteNonQuery();
}
}
}
}
AnswerRe: System.IO.Exception Pin
Dave Kreskowiak12-Oct-07 15:35
mveDave Kreskowiak12-Oct-07 15:35 
GeneralRe: System.IO.Exception Pin
solutionsville12-Oct-07 16:02
solutionsville12-Oct-07 16:02 
GeneralRe: System.IO.Exception Pin
Dave Kreskowiak12-Oct-07 17:00
mveDave Kreskowiak12-Oct-07 17:00 
GeneralRe: System.IO.Exception Pin
solutionsville12-Oct-07 17:07
solutionsville12-Oct-07 17:07 
GeneralRe: System.IO.Exception Pin
Dave Kreskowiak13-Oct-07 3:01
mveDave Kreskowiak13-Oct-07 3:01 
AnswerRe: System.IO.Exception Pin
solutionsville13-Oct-07 9:44
solutionsville13-Oct-07 9:44 
QuestionProblem with launching an external process Pin
Togakangaroo12-Oct-07 10:44
Togakangaroo12-Oct-07 10:44 
AnswerRe: Problem with launching an external process Pin
Ennis Ray Lynch, Jr.12-Oct-07 11:28
Ennis Ray Lynch, Jr.12-Oct-07 11:28 
AnswerRe: Problem with launching an external process Pin
Daniel Grunwald12-Oct-07 23:53
Daniel Grunwald12-Oct-07 23:53 
AnswerRe: Problem with launching an external process Pin
Togakangaroo15-Oct-07 4:34
Togakangaroo15-Oct-07 4:34 
AnswerRe: Problem with launching an external process Pin
Togakangaroo15-Oct-07 7:09
Togakangaroo15-Oct-07 7:09 
QuestionButton Questions Pin
C# Beginner Nick12-Oct-07 10:08
C# Beginner Nick12-Oct-07 10:08 
AnswerRe: Button Questions Pin
Kristian Sixhøj12-Oct-07 10:13
Kristian Sixhøj12-Oct-07 10:13 
GeneralRe: Button Questions Pin
C# Beginner Nick12-Oct-07 10:16
C# Beginner Nick12-Oct-07 10:16 
GeneralRe: Button Questions Pin
Kristian Sixhøj12-Oct-07 10:17
Kristian Sixhøj12-Oct-07 10:17 
GeneralRe: Button Questions Pin
User 665812-Oct-07 10:52
User 665812-Oct-07 10:52 
GeneralRe: Button Questions Pin
Kristian Sixhøj12-Oct-07 10:57
Kristian Sixhøj12-Oct-07 10:57 

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.