Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

How To Asynchronously Read/Write A Named Pipe In C# -


i have windows form hosts custom user control. user control fires seperate process (a .exe) creates , initializes namedpipeserverstream. once process initializes namedpipeserverstream, user control connects namedpipeclientstream.

this works fine.

on windows form have button called "check updates". when button pressed, namedpipeclientstream sends message server, server responds messagebox saying "i've been told check updates". can tell client > server communication working fine.

here's problem. server supposed send message client telling it's checking updates (so user control can update status after verying command received server). whenever happens, locks up.

now going assume because attempting both read , write named pipe @ same time?

below code snippets both server , client. (both these snippets run in seperate threads in respective processes not block ui)

gupdater (the named pipe server):

private void waitforclientcommands() {     // wait connection named pipe client (the gupcontrol)     pipestream.waitforconnection();     pipeconnected = true;      // create streamwriter/streamreader can write/read named pipe     pipestreamwriter = new streamwriter(pipestream) { autoflush = true };     pipestreamreader = new streamreader(pipestream);      // have connection, start reading in messages , processing them     while (true)     {         // skip time if writing pipe         if(iswritingtopipe) continue;          var message = pipestreamreader.readline();         if (message == null)         {             // don't want hog cpu time, if no message reaceived time, wait half second             thread.sleep(500);             continue;         }          switch(message)         {             case "checkforupdates":                 //messagebox.show("told check updates");                 sendmessagetoclient("checking updates, woot!");                 break;             case "downloadupdate":                 messagebox.show("told download update");                 break;             case "applyupdate":                 messagebox.show("told apply update");                 break;         }     } } 

gupcontrol (the named pipe client):

private void waitforservercommands() {     if(!pipeconnected) return;      // have connection, start reading in messages , processing them     while (true)     {         // skip time if writing pipe         if (iswritingtopipe) continue;          // attempt read line pipe         var message = pipestreamreader.readline();         if (message == null)         {             // don't want hog cpu time, if no message reaceived time, wait half second             thread.sleep(500);             continue;         }          messagebox.show("i got message server!!\r\n" + message);     } } 

the following snippet method responsible writing client/server each component. (the difference in name, i.e. sendmessagetoclient , sendmessagetoserver)

private void sendmessagetoserver(string message) {     if(pipeconnected)     {         iswritingtopipe = true;         pipestreamwriter.writeline(message);         iswritingtopipe = false;     } } 

the iswritingtopipe variable simple bool true when respective process attempting write named pipe. initial attempt @ solving problem.

any appreciated!

system.io.pipes.pipestream has method waitforpipedrain() correct way manage coordination between client , server when exchanging messages.

the transmissionmode pipe may affecting things: using byte mode or message mode? i'm not sure how wrapping stream in streamreader plays pipe message mode semantics, example. see this answer more on message mode.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -