|
When Windows Service application is created by VS 2008 via "Windows Service" template it is created as Windows application ( /target:winexe)
For convenience of debugging I modified it so that it can be started both from the command line and as a service using this approach:
static void Main(string[] args)
{
ServiceBase[] ServicesToRun;
TestService srv = new TestService();
ServicesToRun = new ServiceBase[]
{
srv
};
if (Environment.UserInteractive)
{
char KeyChar;
srv.ManualStart(args);
Console.WriteLine("Service started in console mode, press Space key to stop");
Console.WriteLine("Press any letter or digit to send control command (ASCII code +128)");
while (true)
{
KeyChar = Console.ReadKey().KeyChar;
Console.WriteLine("");
if (KeyChar == ' ')
break;
else
{
srv.ManualCustomCommand(KeyChar + 128);
}
}
srv.ManualStop();
}
else
ServiceBase.Run(ServicesToRun);
}
In order for this to work as expected I had to change output type from "Windows Application" to "Console Application" ( /target:exe). Everything currently works the way I expect.
Is this acceptable for Windows Service to be compiled as Console application? Are there any implications? Should I have kept it as "Windows Application" and attached console to it using approach described here: http://www.csharp411.com/console-output-from-winforms-application/ ?
|
|
|
|
|
I would arrange all the stuff that you want to run as the service into another class project. Then you can have the Windows Service project reference to this project for actual usage, and create console app project or windows app project that reference the class project for debugging.
|
|
|
|
|
Windows Services have no GUI so Winexe makes no sense. I always compile service programs as console, but more to the point, I compile the actual service code in a DLL which the program calls.
I do pretty much what you show there and control my services from the command line.
Edit: When I write an application that can be used in console or WinForms mode, I compile it as console.
modified on Monday, July 26, 2010 1:21 PM
|
|
|
|
|
I have this control with numerous buttons, say about 20. Instead of showing ToolTip for each control (it does look cumbersome to me), I would show the tips text on the status strip.
Now the question is, is there a simple way to get the instance of mouse hovering events instead of listing each button's mouse hover events?
I hope I am clear!
P.S.
I happened to find this in my Visual Studio 2010. I think this one is the answer. Can anyone explain to me on how to use this...
this.Controls_MouseHover(object sender, EventArgs e)
Thanks in Advance!
|
|
|
|
|
this is what I have but this didn't show the name of control in statusStrip when hovering the numericUpDown control.
ToolStripStatusLabel tssl = new ToolStripStatusLabel();
int status = 0;
int xCurrentLoc = 0;
int yCurrentLoc = 0;
int zCurrentLoc = 0;
public MotorApp()
{
InitializeComponent();
motor.OpenPort();
rbCircle.CheckedChanged += new EventHandler(SelectAntennaShape);
rbSquare.CheckedChanged += new EventHandler(SelectAntennaShape);
statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { tssl });
CreateMouseHoverEvents(this);
}
private void CreateMouseHoverEvents(Control currentControl)
{
foreach (Control ctrl in currentControl.Controls)
{
if (ctrl is GroupBox)
CreateMouseHoverEvents(ctrl);
else
{
ctrl.MouseHover += new EventHandler(Controls_MouseHover);
ctrl.MouseLeave += new EventHandler(Controls_MouseLeave);
}
}
}
void Controls_MouseLeave(object sender, EventArgs e)
{
tssl.Text = "";
}
void Controls_MouseHover(object sender, EventArgs e)
{
Control ctrl = (Control) sender;
tssl.Text = ctrl.Name;
}
|
|
|
|
|
Hi,
After transferring PNG images to an FTP server, I am unable to open them as they are being corrupted. My code is as below:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://... etc.");
request.UsePassive = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("username", "password");
StreamReader sourceStream = new StreamReader(fileLocalDir);
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
Another thing to add - when I download the file from the FTP server and open in IrfanView, the error below is displayed:
"C:\Folder\file.png: Can't read file header! Unknown file format or file not found! (For unicode file names, please activate the Unicode PlugIn in 'Properties -> Languages')"
Thanks for any assistance,
Anthony.
|
|
|
|
|
You're using the wrong type of stream. Maybe a BinaryReader would be better.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Thanks for your response Nagy.
I have modified my code to use BinaryReader .
I'm still able to transfer the files, but they end up being ~60% the size of the originals. I'm still unable to view the files due to corruption. Please can you advise whether my code is trying to do the right thing or not (see below)?
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftpuser...etc");
request.UsePassive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("username", "password");
BinaryReader br = new BinaryReader(File.Open(fileLocalDir, FileMode.Open));
FileInfo info = new FileInfo(fileLocalDir);
byte[] testArray = new byte[info.Length];
int i;
for (i = 0; i < info.Length; i++)
{
testArray[i] = br.ReadByte();
}
request.ContentLength = i;
try
{
Stream requestStream = request.GetRequestStream();
requestStream.Write(testArray, 0, i);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
}
Regards,
Anthony
|
|
|
|
|
i have created a crystal report with 3 table know i want to put a selection formula in a particular column of table but it is not working
what i have done is this
crystalReportViewer1.SelectionFormula = "{NewSampleEntrys.RecvdDate}={?EDOR}";
crystalReportViewer1.Refresh();
plz give some idea guys......
|
|
|
|
|
Hi all,
I'm trying to write a C# app to emulate the search functions in Windows Explorer, including "find in files" (otherwise I wouldn't need the help!)
I figure there must be part of the Win32 API that performs the find in files function for a set of files, but don't know the name. Can anybody give me any pointers?
Thanks,
Chris
|
|
|
|
|
c2423 wrote: I figure there must be part of the Win32 API that performs the find in files function for a set of files
Not that I know of.
c2423 wrote: Can anybody give me any pointers?
Indexed or non-indexed files? If it's indexed, you might want to interface with Windows Search[^]. Otherwise, it'd still be creating a list of files, and searching them the old-fashioned way.
I are Troll
|
|
|
|
|
Thanks for the response.
Unfortunately I've no control of whether files are indexed or not. I'll have a look at Windows Search though - maybe that will help a bit...
Not to sound completely stupid, but what do you have in mind when you say the old-fashioned way? I'm happy searching text files but not Word, Excel etc?
|
|
|
|
|
c2423 wrote: I'm happy searching text files but not Word, Excel etc?
That's why both Windows Search and Google Desktop employ plugins to index a specific filetype. To quote;
MSDN states: Windows Search currently supports the indexing of over 200 types of items (such as .txt, .html, and .xml file formats) and can work with multiple types of data stores (such as the NTFS file system and Microsoft Outlook).
Searching an index is also functionally different from searching a file; the index isn't updated continuously.
I are Troll
|
|
|
|
|
Interesting information. Looks like I might have to think of another approach to it by using plugins.
Thanks for the help!
|
|
|
|
|
You're welcome
|
|
|
|
|
If you just want to search through files, you might want to consider using the IFilter interface which allows you to read things like PDF files, Word docs and the likes. More details are here[^].
"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,
does anybody know how to render an image on the background of text in rich text box just like watermark.
Best regards
|
|
|
|
|
|
simply it doesn't work. it show white background.msdn says:
This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
This property is not relevant to this class.
but thanks for attention.
waiting for other answers
|
|
|
|
|
You'd have to write your own Paint handler, as done in this[^] article
I are Troll
|
|
|
|
|
Hi,
I have a picture box and loaded a image. I zoomed the Picture box and tried to draw rectangle. when i draw rectangle downwards, picture box also moves down.
how to achive this...
Thanks in advance...
|
|
|
|
|
i want to use ajax in content page
i have script manager on master page
in content page i have following code
<asp:Content ID="Content2" ContentPlaceHolderID="MainContents" runat="server" EnableViewState="true">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged ="checkchange" AutoPostBack ="true"/>
<asp:UpdatePanel ID="updatePnl" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server" visible="false" ></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1" />
</Triggers>
</asp:UpdatePanel>
</asp:Content>
on server side i have following
protected void checkchange(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
TextBox1.Visible = true;
Label1.Text = Label1.Text + "HEllo";
}
else
{
TextBox1.Visible = false;
Label1.Text = Label1.Text + "bye";
}
}
problem is checkchange call just once
if i click towice on check box it does not works
|
|
|
|
|
Put the checkbox inside the updatepanel
|
|
|
|
|
i have try this but same problem and error is
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.2; .NET4.0C; .NET4.0E)
Timestamp: Mon, 26 Jul 2010 10:19:37 UTC
Message: Unknown runtime error
Line: 345
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
Message: '__EVENTTARGET' is null or not an object
Line: 482
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
Message: '__EVENTTARGET' is null or not an object
Line: 482
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
Message: '__EVENTTARGET' is null or not an object
Line: 482
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
Message: '__EVENTTARGET' is null or not an object
Line: 482
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
Message: '__EVENTTARGET' is null or not an object
Line: 482
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
Message: '__EVENTTARGET' is null or not an object
Line: 482
Char: 9
Code: 0
URI: http://localhost:4099/ScriptResource.axd?d=9I1lWtAvVqWN1mD9glifsmEaMOiOLiTKjnBQwe4NQFLjuZpRoCN_LRiI-oQlHO1ffCWMttDUGTSGUEn_n-0ZNQXbP7japojTJ_LVrzCwdLJYzGHv0-QESNieL9JuFlAo0&t=ffffffffec2d9970
how i can solve this
|
|
|
|