Sunday, March 10, 2013

Control accessed from a thread other than the thread it was created on

Share/Save/Bookmark

BackgroundWorker and some basics around it.

Never thought i would get a chance to work with win forms. Here i am dancing with it.
I think its time for me to learn some basics about it.
I developed the app but its hanging while its working i.e executing the lengthy code.
I would not worry about it much but then the running information that i'm displaying on the form is not getting displayed due to it.

So what's the solution? BackgroundWorker
Yes, App gets hung as the entire operation was running in the same thread of the process.
so to avoid it a new thread must be spawn where the operations should run asynchronously.
Instead of cracking my head on spawning threads and handling them, .Net framework already
have a Class BackgroundWorker that supports this with all necessary events.

Here it is how i used it
BackgroundWorker bgWorker = new BackgroundWorker();
bgWorker.WorkerSupportsCancellation = true;
bgWorker.DoWork += DoWork;
// run the worker in async mode to avoid the app running smoothly without hanging
bgWorker.RunWorkerAsync();

public void DoWork(object sender,DoWorkEventArgs args)
{
//time consuming operations go here
}

That makes the app run cool but brought another issue
Cross-thread operation not valid: Control 'control1' accessed from a thread other than the thread it was created on
So i have to use the below delegate methods to access the objects that are created in a
thread different from current.Be aware that delegate can set only properties of the object
but cannot call any methods on it.

 delegate void SetControlValueCallback(Control oControl, string propName, object propValue);
        private void SetControlPropertyValue(Control oControl, string propName, object propValue)
        {
            if (oControl.InvokeRequired)
            {
                SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
                oControl.Invoke(d, new object[] { oControl, propName, propValue });
            }
            else
            {
                Type t = oControl.GetType();
                PropertyInfo[] props = t.GetProperties();
                foreach (PropertyInfo p in props)
                {
                    if (p.Name.ToUpper() == propName.ToUpper())
                    {
                        // append the data
                        //string existingValue = p.GetValue(oControl, propValue).ToString(); ;
                        p.SetValue(oControl, propValue, null);
                    }
                }
            }
        }




Subscribe

Tuesday, March 5, 2013

SharePoint 2013 Search Features & Administration

Share/Save/Bookmark

SharePoint 2013 Search Preview
You must be already aware that Search in SharePoint 2013 is no more as a different license similar to FAST for SP2010. FAST is now integrated in SP2013.
Below is the screen that shows what can be done as part of search administration.
Note that all these screens are taken from Sharepoint Online(Office 365). UI might differ but the features should be same in 2013 server.


Manage Schema - Allows you to configure/map crawled/managed properties. Now each managed property got setttings that include if it can be searchable/queryable/refinable/sortable on search results page without any additional xslt or xml configuration in search webparts.


Manage Authoritative Pages - Here specific content from an url/site can be ranked top over the other urls/sites. Both promotion and demotion of ranking can be done by just providing the urls.

Query Suggestion Settings - This was already there which is similar to google auto suggestions. As in when the user types a keyword or text in search text box, suggestions gets populated.
Note that for these suggestions to work, atleast 5-6 times a content link should have been accessed or clicked that result in a search. Now you have an option in UI to export or import the suggestions.


Manage Result Resources - SP2013 replaced search scopes with result sources that includes content source configuration, federated location selection and any query transformation settings using a built in query builder(no more caml query builder). SP2013 boosted its search and is all geared up with webparts driven by search. CQWP is now replaced by Content search webpart that can have a query build on top these sources to fetch results or data.


Manage Query Rules - Rules is also a new name with few settings carried from SP2010 and much more settings. Admins can configure rules on searches and if it matches a corresponding action is taken(like promoting results or ranking). This is where Best bets will be configured as well.

Manage Query Client Types - This feature allows to prioritize the execution of search query based on the type of application the request has come from. Allows to manage query throttling based on the priorities configured here. By default this option is OFF.


Usage Reports - Here admin can see the pre configured reports on search queries that will pull the data in excel format. SP2013 now do not have an analytics service application but integrated and improved as part of search component. Analytics are two types in SP2013

  •  Search Analytics - Analyzes the content on index server to improve the search relavance and for the reports
  •  Usage Analytis - Analyzes user actions/events
  
Subscribe