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.

.net - BeginReceive in a separate thread -


for reason, need beginreceive on separate thread, example :

    public void waitfordata()     {         thread t = new thread(waitfordatathread);         t.start();     }      public void waitfordatathread()     {         try         {             csocketpacket thesocpkt = new csocketpacket();             thesocpkt.thissocket = m_socclient;             m_asynresult = m_socclient.beginreceive(thesocpkt.databuffer, 0, thesocpkt.databuffer.length, socketflags.none, ondatareceived, thesocpkt);         }         catch (socketexception se)         {             messagebox.show(se.message);         }     } 

but i've received error right after beginreceive call, ondatareceived instantly raised, in event call endreceive method, , error thrown : "the i/o operation has been aborted because of either thread exit or application request".

but if remove separate-thread part (like directly call waitfordatathread(), without going through waitfordata() method), works fine.

if wondering why need create separate thread, because need call beginreceive during event generated different thread different class. pretty same creating new thread sample above, , need make work.

is there way can this??

found answer on msdn (documentation of socket.endreceive):

all i/o initiated given thread canceled when thread exits. pending asynchronous operation can fail if thread exits before operation completes.

you have make sure, thread start socket-operation not exit until done socket i/o.

a workaround use threadpool thread, described here.


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 -