drupal hit counter
Jerry Huang | C#

Jerry Huang apps and developing apps

Translation between WP and Win8 Metro series: loading byte array into BitmapImage

1. November 2012 14:07 by Jerry in C#, Win8 Development, Windows Phone Development

WP

Code
1
2
3
 byte[] frameBuffer;BitmapImage.SetSource(new MemoryStream(frameBuffer, 0, frameBuffer.Length));

Win8

Code
1
2
3
4
5
  var ms = new Windows.Storage.Streams.InMemoryRandomAccessStream();ms.AsStreamForWrite().Write(frameBuffer, 0, frameBuffer.Length);ms.Seek(0);BitmapImage.SetSource(ms);

it looks to me that Win8 just making thing complicated:(

Translation between WP and Win8 Metro series: async anonymous method in Win8

1. November 2012 13:48 by Jerry in C#, Win8 Development, Windows Phone Development

As I mentioned previously, I'm trying to develop a Win8 Metro version of IP CAM Coontroller, so I'm basically translating the WP coding into Win8. I'm going to post a series of blog post to record (and so benefit those googler with same problem) some of the interesting issue and topic.

WP coding:

Code
1
2
3
4
5
6
 Deployment.Current.Dispatcher.BeginInvoke(() =>{//do something here});

WIN8

Code
1
2
3
4
5
6
7
  Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,new Windows.UI.Core.DispatchedHandler(() =>{//do something here}));

This is not end of the story, by using the RunAsync like above, you will get a compiler warning from VS2012, and it's interesting that if you assign the returning result (of RunAsync) to a variable, the warning goes away. So the final version is like:

Code
1
2
3
4
5
6
7
  var dummy = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,new Windows.UI.Core.DispatchedHandler(() =>{//do something here}));

just for fun: sleep sort

29. June 2011 15:02 by Jerry in C#

there are some other versions of implementation in different programming languages, here is my c# version and I believe this sort algorithm will be very hot soon:)

Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
	using System;using System.Collections.Generic;using System.Text;namespace SleepSort{class Program{static void Main(string[] args){int[] ints = { 1, 4, 2, 6, 3 };foreach (int i in ints){SleepSort ss = new SleepSort(i);System.Threading.Thread t = new System.Threading.Thread(ss.Sort);t.Start();}}}public class SleepSort{int i;public  SleepSort(int i){this.i = i;}public void Sort(){System.Threading.Thread.Sleep(i);Console.WriteLine(i);}}}