C# Windows Service won't start
When I try to start my c# service it says:"starting" for a second and it
turns back to being "stopped" What can be the problem? I had the same code
before, and it worked but made some changes in the code now and it stopped
working. Here is what I added to my code:
App Config:
<add key="cut-copy" value="copy"/>
Normal code:
private void fileSystemWatcher1_Created(object sender,
System.IO.FileSystemEventArgs e)
{
String cut_copy = ConfigurationManager.AppSettings[@"cut-copy"];
if (cut_copy == "copy")
{
cut = false;
}
else
{
cut = true;
}
if (WaitForFileAvailable(e.FullPath, TimeSpan.FromSeconds(10)))
{
var file = Path.Combine(source, e.Name);
var copy_file = Path.Combine(target, e.Name);
var destination = Path.Combine(target,
Path.ChangeExtension(source, Path.GetExtension(source)));
if (File.Exists(file))// Check to see if the file exists.
{ //If it does delete the file in
the target and copy the one from the source to the
target.
File.Delete(copy_file);
File.Copy(e.FullPath, Path.Combine(target, e.Name));
}
else// If it doesn't, just copy the file.
{
if (cut == true)
{
if (File.Exists(file))// Check to see if the
file exists.
{ //If it does delete the
file in the target and copy the one from the
source to the target.
File.Delete(copy_file);
File.Move(Path.Combine(e.FullPath,
e.Name), target);
}
}
else
{
if (File.Exists(file))// Check to see if the
file exists.
{ //If it does delete the
file in the target and copy the one from the
source to the target.
File.Delete(copy_file);
File.Copy(e.FullPath, Path.Combine(target,
e.Name));
}
}
//under this is more code that didn't change
}
What am I doing wrong?
No comments:
Post a Comment