Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://www.c-sharpcorner.com/uploadfile/aa04e6/how-to-implement-oncustomcommand-method-in-windows-service-application/" rel="nofollow">OnCustomCommand</a> override, but this only takes an integer as an argument and does not support passing strings to the service.</p> <p>The other options would be to create a <a href="http://www.codeproject.com/Articles/38160/WCF-Service-Library-with-Windows-Service-Hosting" rel="nofollow">WCF service</a> or use <a href="http://www.codeproject.com/Articles/1111/How-To-Host-NET-Remoting-Objects-in-Windows-Servic" rel="nofollow">Remoting</a> to pass the information you need to the service and call the delete method.</p> <p>EDIT: to respond to a question in the comments about how to use OnCustomCommand in a very strange way is as follows.</p> <p>In the service you would need something like this.</p> <pre><code>private const int CMD_INIT_DELETE = 1; private const int CMD_RUN_DELETE = 0; private bool m_CommandInit = false; private StringBuilder m_CommandArg = new StringBuilder(); protected override void OnCustomCommand(int command) { if (command == CMD_INIT_DELETE) { this.m_CommandArg.Clear(); this.m_CommandInit = true; } else if (this.m_CommandInit) { if (command == CMD_RUN_DELETE) { this.m_CommandInit = false; this.deleteFile(this.m_CommandArg.ToString()); } else { this.m_CommandArg.Append((char)command); } } } </code></pre> <p>In the windows form application you would have something like this</p> <pre><code>private const int CMD_INIT_DELETE = 1; private const int CMD_RUN_DELETE = 0; private void RunServiceDeleteMethod(string delFolder) { serviceController1.ExecuteCommand(CMD_INIT_DELETE); foreach (char ch in delFolder) serviceController1.ExecuteCommand((int)ch); serviceController1.ExecuteCommand(CMD_RUN_DELETE); } </code></pre> <p>THIS IS NOT TESTED and only a proof of concept. Again, I DO NOT recommend doing it this way and the above example is only to show how NOT to do this type of communications between desktop applications and services.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload