c# - I can't use a "kill" process in my code. (its underlined with red) -
i want press button, , when button activated, close application desire. example if open notepad, want press button , close notepad. reason, cannot use kill
or close
command underlines red. building application in c#. here code.
public eventhandler<speechrecognizedeventargs> srecognized { get; set; } public form1() { initializecomponent(); } void srecognize_speechrecognized(object sender, speechrecognizedeventargs e) { if (e.result.text == "alice present") { soundplayer sndplayer = new soundplayer(ai.properties.resources.my_name_is_a_l_i_c_e); sndplayer.play(); } if (e.result.text == "open notepad") { process notepad = process.start("notepad.exe"); } if (e.result.text == "close notepad") { btnn.performclick(); } } private void btnn_click(object sender, eventargs e) { process notepad = process.kill("notepad.exe"); }
lets make simple. create process
field , use everywhere:
private process pnotepad; //process field void srecognize_speechrecognized(object sender, speechrecognizedeventargs e) { if (e.result.text == "alice present") { soundplayer sndplayer = new soundplayer(ai.properties.resources.my_name_is_a_l_i_c_e); sndplayer.play(); } if (e.result.text == "open notepad") { //starting process "notepad" pnotepad = new process(); pnotepad.startinfo.filename = "notepad.exe"; pnotepad.start(); } if (e.result.text == "close notepad") { btnn.performclick(); } } private void btnn_click(object sender, eventargs e) { //kill process if running if(pnotepad != null && pnotepad.hasexited == false) pnotepad.kill(); }
Comments
Post a Comment