CLR Debugging API

Leave a comment

So in some advanced debugging situation, we have to write code to reflect the current managed variables and stacktrace.

John, Robbins mentioned in <Debugging with .Net 2.0 Application> as follow:

http://blogs.msdn.com/b/frankred/archive/2004/08/04/207976.aspx

http://blogs.msdn.com/b/junfeng/archive/2004/08/08/210666.aspx

http://msdn.microsoft.com/en-us/library/bb384548.aspx

http://www.microsoft.com/downloads/details.aspx?FamilyID=38449A42-6B7A-4E28-80CE-C55645AB1310&displaylang=e&displaylang=en

That’s really extremely excellent!!!

Windows 8 Programming Summary

Leave a comment

As you know, Microsoft release Windows 8 recently. As MSDN Subscriber, you can download the windows 8 developer preview  and install the virtual system[see my previous post about installation of windows 8 on virtualbox].

Basically, windows 8 is really a kind of COM “reimagined” [cited from Matt,Merry’s speech], and Microsoft try to build cross-language[sure ,Application development language in User application space] based on Windows Platform, instead of something tried with MSIL  in virtual system.

For Application developer, the world seems turn back to 10 year ago, when we still keep love with COM[Still remember IUnknown, Dispatcher, the amazing API QueryInterface, and Thread Apartment, etc… Win32 Dll…].

Actually not yet, refer to http://www.iamraf.net/News/deep-diving-winrt-and-metro-style-apps-for-windows description. Now windows application consists of :

  • Metro Application – I’d like to call it Metro Style Applicaiton [I like Raf’s idiom, just a kind of new working style for windows application. The kernel of application still is dispatched to IPC, etc]
  • Classic Desktop Application – tradional windows application style

The core of User space application has been totally changed into COM with metadata. Take Metro application as example, wmahost as service host to invoke DCOM object and generate application with its own resource based on platform API.

As metadata built on platform[not depends on virtual system], the runtime performance has the possibilities to enhance a lot, esp. for language out-of-virtual system. We say, c++ is back, King is back.[I questioned that C++ Extension is a kind of something like Objective-c, similiar].

Please check up with Raf’s description, great*N post, if you want to know the story behind, not satisfy to just work it out.

And if you have time, please check up with Matt’s speech on windows 8 build, great speech.

Thing come back, What do you need to do here for real development preparation? [Perhaps, just take a note for what I have done here.]

  1. Metro application Guide – http://social.msdn.microsoft.com/Forums/en-US/toolsforwinapps/thread/12057f17-2f6c-422e-836e-47bcb1656a5d
  2. However, if you try to do something with IPackageDebugSettings [win32 API] to enable debug or something different from standard metadata definition of platform COM, you have to install Visual Studio 11 Ultimate developer preview to support both Metro and Desktop application.

By the way, VS2011 Ultimate depends on some components, which are included inside VS2010.[strange ^_^, that’s why it’s pre-developer version]. So take care of that, in case you meet with installation error.

The simplest solution is to install VS2011 side with VS2010, However, the final solution is to check up with installation error, and install missing component separately.

OK, ready, go to Metro application:

  1. http://code.msdn.microsoft.com/windowsapps – Metro application sample, for Application developer, it’s sufficient.
  2. http://blogs.msdn.com/b/b8/ – Windows 8 team blog
  3. My favoriate – http://msdn.microsoft.com/en-us/library/windows/desktop/hh405363 Metro COM Programming interface, amazing!!! you can do a lot of things, Just as Matt has bee done in http://channel9.msdn.com/events/BUILD/BUILD2011/PLAT-875T. amazing and awesome details, I like it, that’s the real world looks like.

Though just a kind of links and video on channel 9, it’s already a great changes.

So basically for Metro/Desktop application in windows 8 , if you just use the standard platform/C# API, it’s cross-language. based on metaCOM, you can do things you like.

However, for me, the powerful application in windows 8 application, will look like what Raf has done for DebugEnabler[winrt.codeplex.com]. Mix-c++ language programming [Guy, just c++, why mixed?], to bind Windows Platform COM interfaces, STL, WRL together.

And as Charle posted in GoNative9++ facebook, COM interop die! The only thing here is C++ [precisely, C++ Extension, and Portable], Just check up with Herb’s speech in Windows 8 Build conference.

Now C++ world become Clean, Safe, and Fluent. Hmmm, as developer, I don’t want to be lazy, and c++ is a way to keep me.

Windows Phone xaml

Leave a comment

My presentation at //build

http://channel9.msdn.com/Events/BUILD/BUILD2011/APP-831T

Clean internal session for Password in IE[or WebBrowser based on IE]

Leave a comment

http://www.alphatecit.com.au/code-snippets/facebook-c-sdk-multiple-login-problem-resolved/

INTERNET_OPTION_END_BROWSER_SESSION
42

Flushes entries not in use from the password cache on the hard disk drive. Also resets the cache time used when the synchronization mode is once-per-session. No buffer is required for this option. This is used by InternetSetOption.

http://blog.prabir.me/post/Facebook-CSharp-SDK-Writing-your-first-Facebook-Application.aspx

Windows 8 developer preview installation

Leave a comment

As you know, in windows 8 build conference [this 13- 16], Microsoft already unveiled Windows 8 developer version for us.

As I’m developer, so choose Windows Developer Preview with developer tools English, 64-bit (x64), about 5GB size.

  • Virtual system preparation:

Here, I introduce sun’s virtualbox as host, http://www.virtualbox.org/wiki/Downloads with version 4.1.2.

Let’s rock…

1, Create new virtual system

step 1 - Create new virtual system

step 2 - choose Windows 7 (64bit)

Step 3 - Create new virtual disk

Step 4 - Select Virtual Disk Type

Step 6 - Dynamic Disk Type

Step 7 – Create Virtual Disk with Dynamic Max Size

OK

OK, then we have to configure boot ISO and Visualization option [As 64 bit virtual system is required for Windows 8 64bit iso booting.]

And you have to enable your BIOS with Visualization option, if your computer couldn’t support visualization, I’m really sorry for you….

Step 8 - System Configuration

Step 8 - Mount your ISO disk

Step 9 - Select your iso

Step 10 - Rock Guys

2, Logging into your windows 8 system, change your screen resolution to larger than 1024. Then you can develop with your Visual studio 2011, with Grid/New application.

Screen shot for Windows 8

Update your screen resolution

Cheer up with Visual studio 2011

Win8 New UI Philosophy

Leave a comment

http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1004

Is it still windows, which we are familiar with? Change is the only constant thing in the varying world.

Impossible is nothing, Yeah, Microsoft learn a lot from Apple, not just learn, but also a kind of re-creation. Wooo… That’s why I keep learning the MacOSX, the new world.

Let’s rock out of bottle.

VSTemplate&MSBuild Category

Leave a comment

Unload VSPackage Project, then add MSBuild XML setting: http://msdn.microsoft.com/en-us/library/5dy88c2e.aspx

<!– To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name=”BeforeBuild”>
</Target>
–>
<Target Name=”AfterBuild”>
<ItemGroup>
<!– Mashup and WebService of Authoring Category, Orlando, 2011-08-18 –>
<AuthoringZipItemFilesToCopy Include=”.\$(BaseIntermediateOutputPath)$(Configuration)\HtmlMashupAuthoring.zip” />
</ItemGroup>
<Message Text=”Copying Zip Files to runtime folder”>
</Message>
<!– Mashup and WebService of Authoring, Orlando, 2011-08-18 –>
<Copy SourceFiles=”@(AuthoringZipItemFilesToCopy)” DestinationFolder=”..\$(Configuration)\Templates\ItemTemplates\MashupWebService Authoring” SkipUnchangedFiles=”true”>
</Copy>
</Target>
<Import Project=”$(MSBuildExtensionsPath)\Microsoft\VisualStudio\DSLTools\v10.0\Microsoft.DSLTools.targets” />
</Project>

Refer to :

ToString() with Parameter and Parse/TryParse with parameters

Leave a comment

When using object.ToString(), or <primitive>.Parse(), TryParse(), any more ideas?

Ya… Es ist…

  1. Which language and Culture are you handling with?
  2. Do you want to format via IFormattable interface or parsing it?

MSDN Link :

  •   Help View Home/Visual Studio 2010/.Net Framework 4/.Net Framework Core Development/Working with Base Type/Formatting Types or Parsing Strings [strongly recommend]
  •   CLR via C# Version 3, Jeffery Richter – Page 309

Just shared with you the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Globalization;

namespace _14_Strings
{
class Program
{
/// <summary>
/// Static method for formatting of Deutsch string -> Help View Home/Visual Studio 2010/.Net Framework 4/.Net Framework Core Development/Working with Base Type/Formatting Types or Parsing Strings
/// Jeffery Richter – Page 309
/// </summary>
static void IFormatProviderTest()
{
//foreach (CultureInfo item in System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures)) //CultureTypes Enumeration
//{
//    Trace.WriteLine(item.ToString());
//}
decimal lNumericBase = 10000000L;//Int64->long
Trace.WriteLine(lNumericBase.ToString(“C”, new CultureInfo(“de-DE”)));
//Trace.WriteLine(lNumericBase.ToString(“D”, new CultureInfo(“de-DE”))); //Invalid format
Trace.WriteLine(lNumericBase.ToString(“N”, new CultureInfo(“de-DE”)));
string strNumericBase = lNumericBase.ToString(“N”, new CultureInfo(“de-DE”));

long number;
IFormatProvider provider = CultureInfo.CreateSpecificCulture(“de-DE”);

if (long.TryParse(strNumericBase, NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, //NumberStyles.Number -> Group NumberStyles Enumeration
provider, out number))
{
Trace.WriteLine(number);
}

strNumericBase = lNumericBase.ToString(“N”, new CultureInfo(“de-DE”));
if (long.TryParse(strNumericBase, NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, //NumberStyles.Number -> Group NumberStyles Enumeration
provider, out number))
{
Trace.WriteLine(number);
}
}

static void Main(string[] args)
{
Program.IFormatProviderTest();
}
}
}

Comparison in Run-time:


C# STA Thread “Message Loop”

Leave a comment

seems a little bit impression, what’s the hell of Thread Message Loop.

  • Use Case – we have a STA DLL, which is exposed for us several COM/COM+ methods. And internally such DLL will store internal “status” cache, for instance STA instance, SA&G.
  • Key Points
  1. Explicit STA Thread construction – Thread.setApartment(STA/MTA). MTA is default setting.
  2. Supposed we call start(), and stop() for default instantiation logic of DLL, how about additional method called inside thread? Can we? Yes, just do something like Message loop. When performance has been concerned, EventWaitHandle (Mutex, Sep. etc)….

public class MethodProxyInThread
{
public MethodProxyInThread _realProxy;

private bool _isRealProxyStop = false;

private event EventHandler<EventArgs> _eventHandler;

private ThreadLocal<EventHandler<EventArgs>> _handler;

private Func<object, int> _functionalHook;

private EventWaitHandle waitHandle;

private object parameter;

/// <summary>
/// in one thread context
/// </summary>
/// <param name=”_realProxy”></param>
public void startMethod(object _realProxy)
{
if (this._realProxy == null)
{
this._realProxy = _realProxy as MethodProxyInThread;
this._isRealProxyStop = false;
Console.WriteLine(string.Format(“startMethod – {0}”, Thread.CurrentThread.ManagedThreadId));
Console.WriteLine(“startMethod”);

waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
this._handler = new ThreadLocal<EventHandler<EventArgs>>(() => new EventHandler<EventArgs>(this.MethodProxyInThread__eventHandler));
this._eventHandler += this._handler.Value;

//TODO : Call start Method Here
//startCall() here
do
{
Console.WriteLine(string.Format(“loopMethod – {0}”, Thread.CurrentThread.ManagedThreadId));
if (this.waitHandle.WaitOne(5000))//rest if no more action, what time-out? to avoid deadlock!
{
//TODO : invoke conditional method; -> parameters
this._functionalHook.Invoke(this.parameter);//, null, null); //=>asynchorous logic
if (!this._isRealProxyStop)
{
this.waitHandle.Reset();
}
}
} while (!this._isRealProxyStop);
//stopCall() here
this._eventHandler -= this._handler.Value;
this.waitHandle.Close();
Console.WriteLine(“Quit the thread”);
}
}

private void MethodProxyInThread__eventHandler(object obj, EventArgs e) //Guys, why this isn’t working, delegation will be running in ThreadPool
{
Console.WriteLine(string.Format(“MethodProxyInThread__eventHandler – {0}”, Thread.CurrentThread.ManagedThreadId));
this._isRealProxyStop = true;
}

//public void PostTerminalEvent()
//{
//    if (MethodProxyInThread._eventHandler != null)
//    {
//        Console.WriteLine(string.Format(“PostTerminalEvent – {0}”, Thread.CurrentThread.ManagedThreadId));
//        MethodProxyInThread._eventHandler(this, new EventArgs());
//    }
//}

public void PostMessage(Func<object, int> _func, object _param)
{
if (!this._isRealProxyStop)
{
this._functionalHook = _func;
this.parameter = _param;

this.waitHandle.Set();
}
}

public void stopMethod()
{
Console.WriteLine(string.Format(“stopMethod – {0}”, Thread.CurrentThread.ManagedThreadId));
this._isRealProxyStop = true;
}
}

class Program
{
static int PostMessageObj(object _obj)
{
Console.WriteLine(string.Format(“postMethod – {0}”, Thread.CurrentThread.ManagedThreadId));
return 5;
}

static void Main(string[] args)
{
MethodProxyInThread proxy = new MethodProxyInThread();
Thread t = new Thread(proxy.startMethod);
t.Start(proxy);

Thread.Sleep(5000);
proxy.PostMessage(new Func<object, int>(Program.PostMessageObj), 6);
Thread.Sleep(5000);
proxy.stopMethod();
//proxy.PostTerminalEvent();
Thread.Sleep(10000);
}
}

 

Of Course, that’s not the ultimate version, For Message Loop, we need dictionary<enum, Func<object, object>> for checking-up, and parameter lists.

Like it, or some more suggestions… Whatever :-). No-UI SynchronizationContext Solution.

Animation Effect adjustment of WPF

Leave a comment

Refer from Adam, Nathan’ WPF unleashed for 3.5.

  • System.windows.Media.RenderCapacity -> static property Tier and TierChanged event

Tier is 32bit int number, however, the real value is stored in the higher 16 bytes.

int tier = RenderCapability.Tire>>16;

if tier == 0, system will use software rendering;

if tier == 1, system will use hardware rendering sometimes;

if tier == 2 [highest level], system will use hardware rendering, wherever graphic could be rendered by hardware.

-> esp. in tier == 0 system, will be difficult to run multi-animation[with 3D effect or complicated transition] .

  • So how-to for tier == 0 system, 1, remove Animation; 2, eliminate DesiredFrameRate of Storybard[normal case = 60frames/second],


Older Entries