|
I have create one file in c drive which and write in it and try to read from window service . Account:Local System, but it Cann't get any thing
Protected Overrides Sub OnStart(ByVal args() As String)
If Not File.Exists("C:\DevLog.txt") Then
EventLog1.WriteEntry("File Not Exist")
Else
Dim sr As StreamReader = New StreamReader("C:\DevLog.txt")
Dim tempstr As String = sr.ReadToEnd
If tempstr = "" Then
Else
EventLog1.WriteEntry("Get File Name")
st = tempstr
End If
sr.Close()
End If
End sub
Thanks in Advance.
|
|
|
|
|
Hi,
so do you get an error message? Does the file contain something?
Btw. this is an C# forum, and you posted some VB code. Also try to not double post.
Regards
Sebastian
|
|
|
|
|
I have created one text file in File Contain -> "abc or some value"
Account :LocaSystem
protected override void OnStart(string[] args)
{
if (!File.Exists("C:\\DevLog.txt")) {
EventLog1.WriteEntry("File Not Exist"); 5. }
else {
StreamReader sr = new StreamReader("C:\\DevLog.txt");
string tempstr = sr.ReadToEnd;
if (string.IsNullOrEmpty(tempstr)) {
}
else {
EventLog1.WriteEntry("Get File Name");
st = tempstr;
}
sr.Close();
}
}
the error msg is:---Service cannot be started. System.IO.FileNotFoundException: File not found.
I think you get clear idea about problem ...
Thank for reply
|
|
|
|
|
sunstate wrote: the error msg is:---Service cannot be started.
So its not necessarily that it can't read your file. Comment out all your code to do with the file and just write a message to the eventlog to show your sevice is working. Then you will make some progress.
There should be no problem reading a file, many services are file watchers, waiting for files to process.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Without File handling code it will working properly and also get proper eventlog up to the File.Exist()
Thanks for reply
|
|
|
|
|
So now try just checking for file.exists and logging a message. Put it in a try ctach so you can log the full exception details and that should give you some pointers.
Really, this is a basic programming technique for trapping/tracing errors so you should be able to properly identify where it goes wrong and also get the full error message as to why.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
I can´t see any creation of "c:\devlog.txt". Are you shure, you create this file?
|
|
|
|
|
I have create one file in c drive which and write in it and try to read from window service . Account:Local System, but it Cann't get any thing
Protected Overrides Sub OnStart(ByVal args() As String)
If Not File.Exists("C:\DevLog.txt") Then
EventLog1.WriteEntry("File Not Exist")
Else
Dim sr As StreamReader = New StreamReader("C:\DevLog.txt")
Dim tempstr As String = sr.ReadToEnd
If tempstr = "" Then
Else
EventLog1.WriteEntry("Get File Name")
st = tempstr
End If
sr.Close()
End If
End sub
Thanks in Advance.
|
|
|
|
|
Hi all,
I am new to C# development.I have application in which i need to enable / disbale too many toolbar buttons based on the tree node selection,due to this my screens is flickering to a greater extnet...please suggest me a good approach through which i can avoid the screen flickering.
Thanks in advance.....
|
|
|
|
|
You can use Events to trigger the status of the buttons based on the tree view node.
luisnike19
|
|
|
|
|
Hi All,
I wonder if it is possible to insert data from excel cell to access database by using C#?
I really need some information about this, could anyone provide me this?
Thanks in advance
Nine
|
|
|
|
|
|
Thanks for your quick reply, i'll try it
Thanks again
Nine
|
|
|
|
|
I wrote class library (dll) and this library contains one singleton class. Like this;
public class MyList : List<string>
{
private static readonly MyList m_Instance = new MyList();
private MyList()
{
}
public static MyList Instance
{
get { return m_Instance; }
}
}
Client --- WCF --> Server; add item to MyList class, its properly work.
Another Client --- WCF --> Server; add item to MyList class, its properly work.
But;
I have a thread in server side. If this thread add to item to MyList, clients items not contain in the MyList. Actually main problem is I can't see MyList items which are aded by clients in server thread.
I think this problem related about AppDomain. How can I solve it?
Best Regards...
|
|
|
|
|
Doesn't the server exit the application after the first client does its thing?
|
|
|
|
|
|
You already started a thread for this DO NOT start a new one Now you will get no help.
only two letters away from being an asset
|
|
|
|
|
My WCF Service use TcpBinding and host on windows service. I am not use ServiceBehavior InstanceContextMode... Problem not related about WCF.
I wrote class which is MyClass1, this class in server side. This class have a Start() function.
public void Start()
{
Thread thread = new Thread(new ThreadStart(CheckTablesAreChanged));
thread.IsBackground = true;
thread.Start();
}
private void CheckTablesAreChanged()
{
while (true)
{
... ADD ITEM TO MyLIST CLASS ...
}
}
Start() function call when WCF is hoting like this;
host.Open();
MyClass1.Start();
So this side not related about WCF.
In Client side;
Client --> WCF --> Server --> ADD ITEM TO MyLIST CLASS
For example client add 3 ITEM TO MyLIST CLASS, after that I check MyLIST CLASS count property in "CheckTablesAreChanged()" function, MyLIST CLASS count is 0.
|
|
|
|
|
Don't repost: it's very bad form.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
I have noticed my projects are being generated with a back slash at the end of the company name. In my c# projects it has not been a big issue as I can follow the error message and change the source file. But in a WiX project, it is being generated with the msi file. I would like to find the source of this and correct it.
Where do I find this setting?
Thanks all
|
|
|
|
|
nm, I found it in the computer registration....bah!
|
|
|
|
|
Hi All,
See this code below:
string format = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern;
Console.WriteLine("Before Changing:");
Console.WriteLine(format);
Console.WriteLine(DateTime.Now);
Console.WriteLine("After Changing:");
CultureInfo ci = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.Name);
ci.DateTimeFormat.ShortTimePattern = "hh:mm:ss tt";
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = ci;
format = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern;
Console.WriteLine(format);
Console.WriteLine(DateTime.Now);
Console.ReadKey();
Output:<br />
Before Changing:<br />
h:mm tt<br />
10/14/2009 21:47:53<br />
After Changing:<br />
hh:mm:ss tt<br />
10/14/2009 21:47:53
I want the Console.WriteLine(DateTime.Now); will print the date time
now of the application with AM/PM in the end 12h format.
I dont want to use the DateTime.Now.ToString("hh:mm:ss tt") for this action.
How can I change my UI thread/main thread with a CurrentCulture that by default will make the DateTime.Now Time to be with AM/PM(12h time) at the end??
Thanks!
Ronen
|
|
|
|
|
I've just copied and pasted you code and it does exactly what you want
|
|
|
|
|
Hi,
After the change you see in your console AM/PM????
|
|
|
|
|