|
i'm unable to understand this services from that article..
i understood its using service controller class in c#..
but m confused where should i place my code to be executed in it..
it says that the control should be transfered to os after the service is executed. but i want my program to be kept running otherwise it wont be logging keys, or watching files, or killing mentioned processes..
i hope u got my point..
|
|
|
|
|
|
Definitely sounds like you need a Service. They're not difficult.
To be able to control a Service from the command line I do something like:
private enum Action
{
None = 0
,
Status
,
Install
,
Uninstall
,
Start
,
Stop
}
[System.STAThreadAttribute()]
public static int
Main
(
string[] Args
)
{
int result = 0 ;
try
{
Action action = Action.None ;
if ( Args.Length > 0 )
{
System.Enum.TryParse<Action> ( Args [ 0 ] , true , out action ) ;
}
switch ( action )
{
case Action.None :
{
if ( System.Environment.UserInteractive )
{
System.Console.WriteLine ( "Syntax: JunkService STATUS | INSTALL | UNINSTALL | START | STOP" ) ;
}
else
{
System.ServiceProcess.ServiceBase.Run ( srv ) ;
}
break ;
}
case Action.Status :
{
System.ServiceProcess.ServiceController svc =
new System.ServiceProcess.ServiceController
(
srv.ServiceName
,
System.Environment.MachineName
) ;
try
{
System.Console.WriteLine ( svc.Status ) ;
}
catch ( System.InvalidOperationException err )
{
System.Console.WriteLine ( err.Message ) ;
}
break ;
}
case Action.Install :
{
System.Configuration.Install.ManagedInstallerClass.InstallHelper
(
new string[] { System.Windows.Forms.Application.ExecutablePath }
) ;
break ;
}
case Action.Uninstall :
{
System.Configuration.Install.ManagedInstallerClass.InstallHelper
(
new string[] { "/UNINSTALL" , System.Windows.Forms.Application.ExecutablePath }
) ;
break ;
}
case Action.Start :
{
System.ServiceProcess.ServiceController svc =
new System.ServiceProcess.ServiceController
(
srv.ServiceName
,
System.Environment.MachineName
) ;
switch ( svc.Status )
{
case System.ServiceProcess.ServiceControllerStatus.Stopped :
case System.ServiceProcess.ServiceControllerStatus.StopPending :
case System.ServiceProcess.ServiceControllerStatus.PausePending :
{
svc.Start() ;
break ;
}
case System.ServiceProcess.ServiceControllerStatus.Paused :
{
svc.Continue() ;
break ;
}
}
break ;
}
case Action.Stop :
{
System.ServiceProcess.ServiceController svc =
new System.ServiceProcess.ServiceController
(
srv.ServiceName
,
System.Environment.MachineName
) ;
if
(
( svc.Status != System.ServiceProcess.ServiceControllerStatus.Stopped )
&&
( svc.Status != System.ServiceProcess.ServiceControllerStatus.StopPending )
)
{
svc.Stop() ;
}
break ;
}
}
}
catch ( System.Exception err )
{
System.Console.WriteLine ( err ) ;
}
return ( result ) ;
}
(JunkService is a Service I've been fiddling with to learn WCF.)
|
|
|
|
|
If you don't want to make your app a service and don't want to build a listener that listens for a close message, you can achieve your goal by periodically checking for the presence of an "exit" file (in the same directory as the application). The -stop command line argument would simply create the "exit" file and exit, causing all normally running instances of your application to exit.
Caveat: this is a cheesy hack but may meet your needs at a pinch.
/ravi
|
|
|
|
|
Hi all!
I have another post about this issue, but I will try to explain myself a bit better this time (sorry for posting 2 times) since the previous post did not get any attention!
Here's the situation:
I have a WinForms project called WinFormsProj1. I have several settings in this project which are saved in a "user.config" file (which lies in "C:\Users\Kåre Tragethon\AppData\Local\WinFormsProj1\WinFormsProj1.exe_Url_********\VersionNo\user.config"). From my main application (WinFormsProj1) I can find the path of the "user.config" by:
Configuration _usrConfigLoc = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
And then
string _filePath = _userConfigLoc.FilePath;
In the same solution I also have another project called WinFormsProj2. I want to access the user.config file to WinFormsProj1 from my WinFormsProj2 project. How can I find the file path?
I must point out that the path I am looking for is NOT the "C:\Program Files\WinFormsProj1......"!! I am looking for the path of the user.config file which lies in "C:\Users\The User\AppData\Local\AppName\AppName.exe_Url_*********"
|
|
|
|
|
Link[^]
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Query for multiple occurrence in Column in a table
or to count which record is occur multiple time
|
|
|
|
|
This is really a SQL question rather than a C# one. To do this, you can use
select id, count(1) from mytable group by id
having count(1) > 1
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi, all!
Here is the problem:
I'm writting some code that gets HTML page, and then grabs it's content. The content of the page is organized in multiple pages, and navigation between them is done by clicking on the page's number below the records (For example, there are 150 records, displayed in 10 pages * 15 records/page. Therefore, the web page contains 10 hyperlinks to other pages with records). Obviously, in order to get all the information needed, I need to loop through all the pages' links, download their HTML and afterwards parse the information.
The problem is, that I can only download 2 pages from the list. For some unknown reason, my code freeses after it downloads 2 pages. The order of the pages does not matter, for example if I start from page #5, I can only get pages 5 and 6.
According to common sense and VS debugger the problem lies in the method, that downloads HTML code
public delegate byte[] getHTTPdelegate(Uri address);
public void downloadPage(string URL)
{
client = new WebClient();
getHTTPdelegate dl = client.DownloadData;
IAsyncResult ar = dl.BeginInvoke(new Uri(URL), null, null);
while (!ar.IsCompleted)
{
Thread.Sleep(10);
}
rawPage = dl.EndInvoke(ar);
}
After downloading page #2, the application stops, and in a minute ar two throws an unhandled exception stating that operation has timed out.
Please note, that the problem is not "why isn't it working?", but "why does it work only 2 times?", when it should be downloading all the pages.
Any ideas will be highly appreciated.
|
|
|
|
|
The sleep loop is a bad idea and the downloading is not really asynchronous (because you're just waiting for it)
Did you know WebClient has a method called DownloadDataAsync?
I don't know why it's working twice.
|
|
|
|
|
Thanks for a reply, Harlod.
I know about DownloadDataAsync, but I didn't try that. Now, I will try that, and post the result.
UPDATE: I've implemented downloading via DownloadDataAsync, but still the problem of 2 pages remained Also, the same exception was thrown.
modified on Saturday, June 26, 2010 10:11 AM
|
|
|
|
|
im tring to UnSerialize that string:
="1.0"="UTF-8"
<result xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" method="auth.createToken" status="ok">
<error code="21" text="One of the parameter values is invalid" info="api_key"/>
</result>
But when i acess the properties it crash program with a null exception
wheres my class:
[XmlRoot("result")]
public class ResultMessage
{
[XmlIgnore]
public const string StatusOk = "ok";
[XmlIgnore]
public const string StatusFail = "fail";
[XmlAttribute("method")]
public string _method;
public string Method
{
get { return _method; }
}
[XmlAttribute("status")]
public string _status;
public string Status
{
get { return _status; }
}
[XmlElement("error")]
[XmlAttribute("status")]
public int _errorcode;
public ErrorCode ErrorCode
{
get { return (ErrorCode)_errorcode; }
}
[XmlElement("error")]
[XmlAttribute("text")]
public string _errortext;
public string ErrorText
{
get { return _errortext; }
}
[XmlElement("error")]
[XmlAttribute("info")]
public string _errorinfo;
public string ErrorInfo
{
get { return _errorinfo; }
}
public ResultMessage()
{
_errorcode = 0;
}
Thanks
|
|
|
|
|
Hello,
I want to concatenate RTF texts from database and show them in a rich textbox as a single document without loosing formating.
I have one record like this
{\rtf1\ansi\ansicpg1252\uc1\deff0{\fonttbl
{\f0\fswiss\fcharset0\fprq2 Arial;}
{\f1\froman\fcharset2\fprq2 Symbol;}}
{\colortbl;\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue0;}
{\stylesheet{\s0\itap0\nowidctlpar\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}}
{\*\generator TX_RTF32 14.0.520.503;}
\deftab1134\paperw12240\paperh15840\margl1138\margt1138\margr1138\margb1138\widowctrl\formshade\sectd
\headery720\footery720\pgwsxn12240\pghsxn15840\marglsxn1138\margtsxn1138\margrsxn1138\margbsxn1138\pard\itap0\nowidctlpar\plain\f0\fs18\cf3 hello\par }
and another record like
{\rtf1\ansi\ansicpg1252\uc1\deff0{\fonttbl
{\f0\fswiss\fcharset0\fprq2 Arial;}
{\f1\froman\fcharset2\fprq2 Symbol;}}
{\colortbl;\red0\green0\blue0;\red255\green255\blue255;\red0\green0\blue0;}
{\stylesheet{\s0\itap0\nowidctlpar\f0\fs24 [Normal];}{\*\cs10\additive Default Paragraph Font;}}
{\*\generator TX_RTF32 14.0.520.503;}
\deftab1134\paperw12240\paperh15840\margl1138\margt1138\margr1138\margb1138\widowctrl\formshade\sectd
\headery720\footery720\pgwsxn12240\pghsxn15840\marglsxn1138\margtsxn1138\margrsxn1138\margbsxn1138\pard\itap0\nowidctlpar\plain\f0\fs18\cf3 world\par }
The output of first string is Hello & second is World
I want to display this in a RTF Editor as follows
Hello
World
how can I do that? Any help would be appreciated.....
Thanks
Sebastian
|
|
|
|
|
I found a neat little workaround that you could try -
1. Create two instances of RichTextBox in the application.
2. Load the first RTF file into the first RichTextBox control.
3. Select and copy the content in the first RichTextBox control to
Clipboard by calling the SelectAll and Copy methods of the RichTextBox
class.
4. Paste the content (from Clipboard) to the second RichTextBox control by
calling the RichTextBox.Paste method.
That should give you merged rtf text...
|
|
|
|
|
Thanks abhinav...I was thinking this way, & most probably I will fllow this, unless I find a better solution...
thanks for your thoughts
Sebastian
|
|
|
|
|
NRTFTree - A class library for RTF processing in C#[^]
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi All,
I have asked this question twice already in the last hour but for what ever reason I was not able to locate my posts so here I go again. I would like to create a windows app in C# that will insert data from a text file into a table. What can I use to create my table if I'm not creating a web doc? Is it possible to read text file into a record set using C#? I did some research on this topic and only found solutions created in VB5 an VB6. Thank you in advance for your reply.
modified on Saturday, June 26, 2010 1:26 AM
|
|
|
|
|
You might find some clues here[^]. The article addresses the problem of reading text (in csv form) into a recordset. You could then use your recordset to populate a datagrid. If your text file isn't in csv format, look into parsing functions to separate the text into whatever format you need.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
ASPnoob wrote: I was not able to locate my posts
Just go to your home page (see the link at the top of the page with your user name) and click on messages.
It's time for a new signature.
|
|
|
|
|
I checked for him - they weren't there. I suspect he may have posted at the time the site changed over.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
OK thanks. It's just that I've seen this question more than once recently so I assumed (from his userid) that he really was new to the site.
It's time for a new signature.
|
|
|
|
|
i need a very simple chat application can any one help me
to get the basic idea i dont want a complex code
must be simple to understand
|
|
|
|
|
Google!
Try just three words from your question: "simple chat application" and you will get more than 2,000,000 links. Lazy, lazy, lazy...
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
OriginalGriff wrote: Lazy, lazy, lazy...
That doesn't seem fair. Would you read 2,000,000 web pages? Besides, he already started, see the next thread.
|
|
|
|
|
Sorry.
I must remember that nobody wants to read these days.
When I got started, we would have killed for access to 2 web pages worth of info, never mind 2,000,000. We had to go to a bookshop and pay for info! And then read 2,000,000 pages to find the bit we wanted.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|