Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF LINQ collections .NET4 , +
Hi all,
 
i have implemented a Extension method for ICollection f in project that bacically i am trying to do some datagrid related operation on ApplicationIdle state. here is the code.
 
 public static class CollectionExtension
    {
        /// <summary>
        /// Set item Binding to the DataGrid
        /// </summary>
        /// <typeparam name="T">Source type</typeparam>
        /// <param name="Collection"> Collection </param>
        public static void SetItemBinding<T>(this ICollection<T> Collection, DataGrid DataGrid)
        {
            Dispatcher.Invoke((ThreadStart)delegate()
            {
                .....
 
            }, DispatcherPriority.ApplicationIdle, null);
        }
    }
 
But am getting a error in this part of code Dispatcher.Invoke((ThreadStart)delegate()
saying that
Error:
An object reference is required for the non-static field,method or Property. what aould be the issue where am i doing wrong.
Posted 26-Sep-12 2:20am
Comments
Amir Mahfoozi at 26-Sep-12 11:56am
   
Add a dispatcher parameter to your extension method and pass the Dispatcher instance whenever you call this extension method.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have used the Dispatcher, and it does not seem to be very reliable. Had much more luck with tasks: First get a TaskScheduler from somewhere that is on the UI thread:
 
TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
 
Then in the place you need to make changes use a task:
 
Task task = Task.Factory.StartNew(() =>
    {
       //Your code here
    }, CancellationToken.None, TaskCreationOptions.None, uiScheduler);
 
Hope it helps.
  Permalink  
v2
Comments
_AKA_KSN_ at 26-Sep-12 23:23pm
   
Thank you very much.
Clifford Nelson at 27-Sep-12 11:41am
   
Glad to be of help, can you vote on the question also?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141015.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100