C # Eighth session

Source: Internet
Author: User

Let's start with something that's going to last.

One of the key words mentioned in the previous blogs

Async

It's not clear what this is all about, it's just that it's about asynchrony.

As the experiment and self-study as well as the teacher in-depth understanding of the specific use of async

Not much nonsense. Example above

Private async void Button_Click (object sender, RoutedEventArgs e) {int p = 0;//today's expense asks for a sum string val = "Today has been spent";    Val + = p.tostring ();    Val + = "Yuan";    var messagedialog = new Messagedialog ("Operation succeeded", Val); await Messagedialog.showasync ();}

  

Here is a reference to the code in my experiment, here is a dialog box, called asynchronous private after the async declaration and then which statement asynchronous call is preceded by an await. This statement will not occupy the main thread

About implementation I asked the teacher that it would automatically generate an additional thread to complete the statement inside the await

This saves you the trouble of writing thread.

Very convenient ...

Incidentally or the above code can be recalled dialog. This dialog is also useful, and very practical.

Here you can see the effect, there is a self-contained close button, the exception practical code implementation is also very simple

One more word binding ... I said a little last week.

Binding benefits In fact not only can automatically bind background data, and very smart, if I have 8 buttons 8 text to display, and the format content basically the same

Then we can design a binding, and then datasource there are 8 data (to be bound) on it.

will automatically display all the contents of the DataSource.

As well as the datasource inside of the Click event does not need to write a lot, as long as the item to write a click event, and then you can pass information to determine which button you clicked on it.

Like what

void Itemview_itemclick (object sender, Itemclickeventargs e) {//navigate to the corresponding target page, and//Configure a new page by passing the required information as a navigation parameter var itemId = ((Sam Pledataitem) E.clickeditem).  UniqueId; This. Frame.navigate (typeof (Itemdetailpage), itemId);}

This is the jump through Itemid.

No need to write click events for each item

It's also a big killing device for the province code.

The last class teacher spoke about the use of stream, C # There are a lot of stream,stream to read/write files/data, etc., there are FileStream ah BufferedStream corresponding to various formats in various cases of input and output requirements .... It's just a record of the usage of some of the streams in the first experiment.

The first experiment to read the information from the file and to use a byte to save, began to think is to read each one in their own calculation of the binary, and then after the answer to know that the original can be used in binary

Of course, that's the reader thing ...

Paste the code again.

Static voidMain (string[] args) {            byteBYte; ushortCRC =0xFFFF; stringPapath =""; FileStream FStream=NewFileStream (args[0], FileMode.Open, FileAccess.Read); BinaryReader Binread=NewBinaryReader (fstream); Try            {                 while(true) {BYte=Binread.readbyte (); CLACCRC used=NewCLACCRC (); CRC=used.                Crcvalue (CRC, BYte); }            }            Catch(EndOfStreamException e) {ushortCRCexchange1 = (ushort) (CRC &0xff00); ushortCRCexchange2 = (ushort) (CRC &0xFF); CRCexchange1= (ushort) (CRCexchange1 >>8); CRCexchange2= (ushort) (CRCexchange2 <<8); CRC= (ushort) (CRCexchange1 |CRCexchange2); Console.WriteLine ("{0:x}", CRC);            Console.ReadLine (); }        }

Here you can see the usage of our stream, and note that if we want to read the end of the file we need to do a try catch to prevent the endofstreamexception from appearing ...

And there does not seem to be a function to determine whether the file is currently read into the end of the document. This is generally the operation (perhaps I do not know ...). For advice

Other streams, such as BufferedStream, are used to encapsulate the other stream ... I don't know how to use it at the moment. The previous usage was also found.

There are some similar networkstream for network interaction, left to be updated (and dug)

Review the main talk about the Binding,stream and asynchronous threads, Async is actually normal should be used tread to achieve, async I think is a lazy ... The use of thread is also very important. Here we go.

See you next time!

C # Eighth session

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.