Mike Taulty's Blog
Bits and Bytes from Microsoft UK

Browse by Tags

Blogs

Mike Taulty's Blog

Elsewhere

  • Windows 7 & WPF 4.0 Beta – Taskbar programming of jumplists and thumbnail previews

    The other day I had a talk to give which included a little around Windows 7 shell programming in .NET 4.0 Beta 2 and I hadn’t really looked at it so I took a few mins out to take a look at how you can program the Taskbar in Windows 7 from WPF in Visual Studio 2010 Beta 2. I was really looking for a short, snappy screencast to take me through it and I didn’t find one ( which doesn’t necessarily mean that they don’t exist but I did search around a little ) so I made a couple that I’ve embedded here. One is around jumplists; Windows 7 - Programming Taskbar jumplists with Visual Studio 2010 . and the other is around getting thumbnail previews of application windows on the Taskbar; Windows 7 - Programming Taskbar previews with Visual Studio 2010 . You’ll need Visual Studio 2010 Beta 2 to follow along with these; Download Visual Studio 2010 Beta 2 Also, I mention that there is more complete Windows 7 functionality in the Windows API Code-Pack so take a look at that too; Download Windows API Code-Pack and, as always...
  • 13th May – Session at the SQL Servers User’s Group at Microsoft, Reading

    Just a quick plug – tomorrow evening I’m doing a session on ADO.NET Data Services (“Astoria”) at the SQL Server User’s Group at Microsoft, Reading. See here for details; http://sqlserverfaq.com/events/167/Sessions-on-Understanding-ADONET-Data-Services-Windows-7-features-indepth-and-the-usual-SQL-Nuggets-and-Networking.aspx it’d be great to see you there.
  • PropertyChangedNotification Snippets

    If I’ve written code around PropertyChanged notification in Visual Studio once then I must have done it thousands of times so I thought I’d do a quick snippet and drop it here. Snippet for a class that implements INotifyPropertyChanged; <?xml version="1.0" encoding="utf-8" ?> <CodeSnippets  xmlns=" http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet" >     <CodeSnippet Format="1.0.0">         <Header>             <Title>Class with property changed notification</Title>             <Shortcut>pcclass</Shortcut>             <Description>Code snippet for class with property changed notification</Description>             <Author>Mike Taulty<...
    Filed under: ,
  • C# and Optional Parameters

    I talked a little at DevWeek about C# 4 and Visual Basic 10 and, in the C# section of that talk, I talked about optional parameters and named parameters coming into the language. I presented an example class something like this one; class P e r s o n { public void W a l k ( ) { W a l k ( 1 ) ; } public void W a l k ( int h o w F a r ) { W a l k ( 1 , 3 . 0 ) ; } public void W a l k ( int h o w F a r , double s p e e d ) { W a l k ( 1 , 3 . 0 , false ) ; } public void W a l k ( int h o w F a r , double s p e e d , bool c o m e B a c k ) { } } with a method like Walk here which ends up having a number of overloads because I want to offer the calling programmer a bit of convenience around how many (or few) arguments they need to pass to the function. I’ve always found it a bit painful to have to write N methods like this when, really, there’s only one method called Walk and we just want to mark a number of parameters as optional which is exactly what C# 4 will let us do. So, in C# 4 we can do something like; class...
  • DevWeek Follow Up

    I did a couple of sessions at DevWeek this week and had a really good time meeting up with various folks and chatting about technologies. My sessions were on; VB and C# in Visual Studio 2010 Parallel Extensions in Visual Studio 2010 Silverlight and HTML/Javascript interoperability (in Silverlight 2) You can grab the slides from here . I’ll also put them on SlideShare so that they are more generally available. As is 99% the case with me – these are not Microsoft generic slides taken from somewhere else, these are all hand-cranked from me to try and find the best way that I can of telling a story so if they don’t line up with something you saw elsewhere then feel free to assume that I am wrong and the other story you saw was probably the right one :-)
  • C# 4, More scrappy thoughts on dynamic

    NB: This comes from experimentation rather than being some kind of C# guru so apply a pinch of salt to anything and everything and I’ll correct if someone tells me I messed up :-) I’m also not sure I can add a lot around this dynamic feature in C# 4 but I’ve been thinking about some demos around it today so I thought I’d jot it all down rather than go at it piecemeal which is what I was doing here and here . I’m starting to think that life in C# 3.0 was pretty simple :-) I could write code such as; class M y C l a s s { public int A d d ( int x , int y ) { return ( x + y ) ; } } class P r o g r a m { static void M a i n ( string [ ] a r g s ) { object o = new M y C l a s s ( ) ; int r e s u l t = o . A d d ( 1 0 , 2 0 ) ; } } and it won’t compile because the static type of o is object and object doesn’t have a method called Add on it. If I move to C# 4 and drop in the new type dynamic then the compiler is prepared to give me “the benefit of the doubt” and attempt to find the right shape of method on o at runtime...
  • C# 4, Dynamic Overloads

    Another experiment with C# 4 and the “dynamic type”. I was playing with this code below and wasn’t 100% sure what’d happen at the point where we hit the 2 lines that I’ve flagged with a * below. That is – if I’m doing dynamic method resolution and I pass a “dynamic parameter” then are they treated as object or are they treated as their actual types with respect to resolution. You can see how it actually seems to work below; class M y T y p e { public void M e t h o d ( int x , int y ) { C o n s o l e . W r i t e L i n e ( "Int function" ) ; } public void M e t h o d ( string s , string t ) { C o n s o l e . W r i t e L i n e ( "String function" ) ; } public void M e t h o d ( object o , object p ) { C o n s o l e . W r i t e L i n e ( "Object function" ) ; } } class P r o g r a m { static void M a i n ( string [ ] a r g s ) { d y n a m i c d = new M y T y p e ( ) ; d . M e t h o d ( 1 0 , 2 0 ) ; // Calls the int version. d . M e t h o d ( "abc" , "def" ) ; //...
  • Thinking about C# 4.0, VB 10 and Dynamic

    I’ve been thinking a little this week about C# 4.0, VB 10 and the new dynamic abilities. That is, what happens when I do something like; static void M a i n ( string [ ] a r g s ) { d y n a m i c o = G e t S o m e O b j e c t ( ) ; o . A d d ( 1 0 1 ) ; } static object G e t S o m e O b j e c t ( ) { return ( new L i s t & l t ; int & g t ; ( ) ) ; } Now, if you’ve seen the sessions around this (watch this one , read this document ) then you’ll know that in C# 4 this code compiles and works and that a variable declared with dynamic means that the C# compiler is prepared to get into “dynamic resolution and dispatch” for variables (parameters, return values, etc) that are declared as dynamic and that can have different meanings such as; If the object is a plain .NET type then the dynamic work can be done via reflection If the object is a COM object implementing IDispatch then the work can be done via that interface If the object implements IDynamicObject (a new interface in .NET 4.0) then the work can be...
  • Parallel Extensions talk at NxtGen User Group, Coventry

    A big thanks to all the people who came along to my talk on Parallel Extensions at the NxtGen User Group in Coventry last night. The slides that were used should be visible up on SlideShare if you want them for any reason. Note to self: “Coventry is not ‘right next to Birmingham’ and is actually 100 miles from home so takes more like 2 hours than 1 hour so next time don’t say you’ll be home by 10.30pm” ;-)
  • C#, Lambdas, closures, value types

    Blogging this in order that I remember in the future that I have been around this “loop” many times and that this code; int x = 1; Action a = new Action( ( ) => { x++; }); a( ); Console.WriteLine( x ); prints a value of 2 whereas this code; int x = 1; Action< int > a = new Action< int >( ( i) => { i++; }); a( x ); Console.WriteLine( x ); prints a value of 1 and that means that this code; struct MyStruct { public void Set() { flag = true ; } public void Print() { Console.WriteLine(flag); } public bool flag; } class Program { static void Main( string [] args) { MyStruct myStruct = new MyStruct(); Action action = new Action ( () => { myStruct.Set(); }); action(); myStruct.Print(); } } prints a value of true whereas this code; struct MyStruct { public void Set() { flag = true ; } public void Print() { Console.WriteLine(flag); } public bool flag; } class Program { static void Main( string [] args) { MyStruct myStruct = new MyStruct(); Action<MyStruct> action = new Action<MyStruct> ...
    Filed under: ,
  • REMIX UK - "No Silverlight Application is an Island" Code

    I'm just back from REMIX UK down in Brighton where I did a couple of sessions - one on Silverlight and another on Windows Presentation Foundation. Thanks to all who came along and apologies if you were either chatting to me or in my session and thought that I was a little low on energy ( or coherence for that matter :-) ) - I picked up a cold over the previous weekend and was a bit feverish on the Thursday and the Friday. Many thanks go to the nice lady in the Boots 24 hour chemist in the middle of Brighton for selling me some "Day Nurse/Night Nurse" at 9pm on the Thursday night :-) I had a really strange experience in my Silverlight session in that, for the first time ever, I typed a bunch of code onto my keyboard and then looked at the display and instead of it saying something like; string.Format("This is a some message {0}", someObject); it said something like; xydsdf.deerfds.(dfdsf, dfdsfdf) ::; ; and I thought to myself "Uh oh, this session's going to be a bit tricky as it seems that my fingers have stopped...
    Filed under: , ,
  • Messing with Dynamic LINQ Queries

    Mike was chatting to me about how you'd take something like this ( against LINQ to SQL and the Northwind database ); using (NorthwindDataContext ctx = new NorthwindDataContext() { Log = Console.Out }) { string [] values = { "A" , "B" , "C" }; var query = from c in ctx.Customers select c; foreach ( string s in values) { string t = s; // Care to avoid capturing the same value 3 times... query = query.Where(c => c.CompanyName.Contains(t)); } query.ToList(); } Console.ReadLine(); which produces; SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactT itle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Coun try], [t0].[Phone], [t0].[Fax] FROM [dbo].[Customers] AS [t0] WHERE ([t0].[CompanyName] LIKE @p0) AND ([t0].[CompanyName] LIKE @p1) AND ([t0]. [CompanyName] LIKE @p2) -- @p0: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%C%] -- @p1: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%B%] -- @p2: Input NVarChar (Size = 3; Prec = 0; Scale = 0) [%A%] and write a new...
    Filed under: , , ,
  • I'm Missing My Default Parameter Values

    I miss default parameter values from C++. In C# if I have some method Foo; static void Foo( int intValue, float floatValue, string stringValue) { } and there's the possibility that all the parameters can be "optional" then I end up writing something like; static void Foo() { Foo(0, 0.0f, null ); } static void Foo( int intValue) { Foo(intValue, 0.0f, null ); } static void Foo( int intValue, float floatValue) { Foo(intValue, floatValue, null ); } static void Foo( int intValue, float floatValue, string stringValue) { } which is a lot of code when I really just want to say; static void Foo( int intValue = 0, float floatValue = 0.0f, string stringValue = null ) { } and my C++ compiler would have been happy with that but my C# compiler isn't going to be. Pity as I think that the single function definition is a lot nicer than the multiple function definitions. With object initialisation in C# V3.0 you almost feel like writing; public class ArgType { public int intValue = 0; public float floatValue = 0; public string...
    Filed under: ,
  • LINQ to SQL - Tailoring the Mapping at Runtime

    Mats has a post over here about concurrency in LINQ to SQL with a long write-up about issues that he sees in using the framework. I've not read all of it yet because the very first point that he raises sent me off on a bit of a tangent (which does not necessarily provide an answer to any/all of his post - it's just something that it caused me to think about). The first point is - in the case where you (for whatever reason) don't want optimistic concurrency with LINQ to SQL, how would you turn it off globally? As far as I know there's no "override" flag that you can set anywhere to just switch off concurrency checking and (given that the default value for UpdateCheck is Always) you're going to have to visit all the "Column attributes" somehow and tweak that value. LINQ to SQL doesn't offer you the opportunity to customise the code-generation process like the Entity Framework does so there's not much you can do there AFAIK. So, what are the options for tweaking a mapping using the UpdateCheck flag as a particular...
    Filed under: , ,
  • Video: SQL 2008 and FileStream (writing data)

    Short video on working with the new varbinary (max) filestream data type in SQL Server 2008. Hover near the bottom of the player for controls. Double-Click the player for full-screen. I don't have a downloadable version at the time of writing so will update the post later when I have one. The post was updated on 11th March, 2010 - this video can now be found here
    Filed under: , ,