|
Dear All,
I have created a very basic and simple windows service application using c# in vs 2005.
i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running.
the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created.
this the code bellow
protected override void OnStart(string[] args)
{
System.Windows.Forms.MessageBox.Show("Service is start...");
}
i have googled and used topic in msdn to create window service application.
why the message box does not appear when i am starting the service?
|
|
|
|
|
Services do not show UI. They are logged in as adifferent user and can not display data to a desktop. You can use Trace.Assert(false,"Hello");
Natza Mitzi
|
|
|
|
|
yeah you are right, but if we enable the option "Allow User to Interact with Desktop".
we can show UI to the user.
i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.
|
|
|
|
|
Instead you can use a client application that interacts with the service.
Using GUI in services is dangerous
Natza Mitzi
|
|
|
|
|
can you please have more detail on client application and the interaction way between client and server application.
you mean i should call window forms from my installer class.
|
|
|
|
|
This is a suggestion of implementation.
The installer should install both service and application. The service should run independently (treated as a server) and the application should run as a client, post requests and run the service to do what it needs to. The connection between the client application can be implemented using .net remoting and the interaction will be transparent. My preferred way is to implement a service and a client application that runs from the system tray using a notify icon. The client application can have the service controller for starting/stopping/pausing/installing/uninstalling the service.
I saw some articles around the code project with samples of notify icons, service controllers and .net remoting. I hope this helps
Natza Mitzi
|
|
|
|
|
Member 6059028 wrote: Allow User to Interact with Desktop
This is VERY bad practice. I believe you can't even do this in Vista.
|
|
|
|
|
You can't display interface components in a Windows service.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You can - you shouldn't, but you can. Windows Services have a property "Interact with desktop" that allows a user to do precisely this - it's yet another crappy design decision.
"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
|
|
|
|
|
I know, but I was trying to keep it as simple as possible for the guy.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I am trying to figure out if there's a way I can keep an Excel cell updated as follows:
I have created a C# dll, with a function: double pf2GetPrice(string ticker) which returns the price of a ticker, when calling this function in a cell in Excel - it works nicely.
To keep the cell value current, I'd like to loop within the dll and update the calling cell's value.
Can this be done? (i'm guessing it must be possible)
I've only come across this so far, but its not a very good tutorial: http://msdn.microsoft.com/en-us/library/bb687861.aspx[^]
Any advice would be much appreciated,
G
C# dll newbie
|
|
|
|
|
You are trying to do the work from the wrong end, the loop should logically be in the Excel program. I guess you could have the sheet register itself with the DLL and have a time running to update the sheet (how I have no idea but it may be possible).
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why do you think its 'logical' to have the looping in the excel sheet? (to me its more logical to have the dll doing the 'updating' ... leaving the sheet user to not worry about constantly refreshing it.
I'm just thinking about all the dll's out there that keep cell data updated dynamically (bloomberg API for example) ... ?
Therefore I think it must defo be possible
help much appreciated,
g
|
|
|
|
|
Standard OO design, the parent (the dll) has no knowledge of the child (excel). It's like having the web service having to know and keep track of about every subscriber. What happens when you have 2 sheets wanting to get the data from the DLL?
Mind you if the DLL is an abstraction layer between the web service and the excel sheet and is instantiated for each sheet to be serviced then you are right the DLL can do the management. This would give you something like:
Sheet wakes up
Instantiates DLL
DLL gets reference to target cells
DLL starts timer loop
DLL gets data from service (pre difined in DLL)
DLL feeds sheet
DLL repeats
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Ok I see, makes sense yeah
thank you
G
|
|
|
|
|
Dear partners,
i'm a newbie programmer in c# environment.
Can you help me how to get the pixel value in colored image in c#?
thx.GBU
Best Regards,
|
|
|
|
|
This is a task that seems to me to have scope to lead to a general task beyond what a newbie should be doing. In fact, I think that's almost totally guarenteed to be the case, if you're new to C#, you should not be doing any image processing. GetPixel works for a single pixel, but is not efficient for tasks where you need to read lots of them.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Create a bitmap and use the SetPixel method. As I remember it has very bad performance but you should check it for your needs.
Bitmap bmp = new Bitmap(@"D:\1\img.bmp");
Color c = bmp.GetPixel(3, 3);
Natza Mitzi
modified on Monday, March 30, 2009 2:27 AM
|
|
|
|
|
He said get, not set.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Bitmap.GetPixel() is that what you need but remember that this is slow. You can use unsafe code instead.
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
|
|
|
|
|
Hello everyone,
I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method. I am given with the various flat files and corresponding mapping files. These mapping files itself are in XML (.ltm extension). Now I have to generate XML files from the flat files that adhere to the schema of these mapping files. And for this I have to use XML serialization and deserialization process written in c# code.
Why XML serialization/deserialization?
Because I have generated xsd of the given xml mapping files and imported that file into my solution as xsd.cs so that I can have various nodes of this mapping file available to me as a classes. I mean, I can directly write classes belonging to various elements in this mapping file. As a result I do not have to parse these mapping files using Read and Write properties.
I am asked to create the instances of these classes and use the serialize/deserialize methods to get the work done. Now my problem is that I do not know how to exactly create the classes in this situation and go about serialization and deserialization. So can any one help me out in this situation by providing some sample codes/snippets related to my work. It would be great if someone can actually provide me with steps/algorithm to go about this project. Let me specify one more thing, all the mapping files corresponding to different flat files have the same structure, only the text values corresponding to various Elements are different.
Thank you very much.
|
|
|
|
|
SK84 wrote: I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#.
That is the stupidest thing I have ever heard.
SK84 wrote: I am asked
Anyone who asks someone to do production level tasks after 4 weeks of learning a language, gets what they deserve.
SK84 wrote: and use the serialize/deserialize methods to get the work done
I guess you want to write code in those methods that turn the classes in to XML or read them from XML then.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: That is the stupidest thing I have ever heard.
Surely not - if stupid is as stupid does, these people does stoopid.
"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
|
|
|
|
|
Christian Graus wrote: Anyone who asks someone to do production level tasks after 4 weeks of learning a language, gets what they deserve.
I was fixing bugs in C# barely 2 weeks after being hired (never having touched the language before), and thanks to a bureaucratic snafu didn't have a PC for the first 3ish days.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Can you use CommandBehavior.SequentialAccess with data in a VARBINARY column?
I have a downloads pulling from that column but not doing it that way.... here is my code:
int bytesSize = 0;
byte[] downBuffer = new byte[1024];
byte[] buffer = (byte[])cmd.ExecuteScalar();
conn.Close();
MemoryStream ms = new MemoryStream(buffer);
FileStream fs = new FileStream(Path, FileMode.Create, FileAccess.ReadWrite);
while ((bytesSize = ms.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
fs.Write(downBuffer, 0, bytesSize);
WriteTextBox((fs.Length / 1024) + "KB of " + (ms.Length / 1024) + "KB.");
bw.ReportProgress(Convert.ToInt32((fs.Length * 100) / ms.Length));
}
fs.Close();
ms.Close();
The problem is it gets all the data here:
byte[] buffer = (byte[])cmd.ExecuteScalar();
So if I'm correct it is getting ALL of the data there. Which if it is a large file.. not even that large, it pauses there until it gets it.. Now on remote connections it times out because it doesn't have that long. But also the way I have it reports progress when writing to the file, but I want to report progress on downloading the file.
I have seen code used with this for BLOB data, but the column is not the type TEXT.
|
|
|
|