I have a couple of question regarding developing multithreading webparts in SharepointSharePoint. First, let me explain the idea. I have a page with 5-7 different webparts. These webparts are constructed all in the same way, which means:
Now, my first question: Q2
Q2) Do I am right? If not, why?
a) Create an new Thread and then call Thread.join()Thread.join()
c) Or call Page.RegisterAsyncTaskPage.RegisterAsyncTask
in the OnPreRenderOnPreRender
Q3) Since, I am using SPSiteSPSite
and I was reading that this Object is based on COM can I use ThreadPoolThreadPool
or Page.RegisterAsyncTaskPage.RegisterAsyncTask
? In some blog I was reading that ThreadPool does not support COM object, because of the Apartment mode (MTA vs STA). Moreover I think that Page.RegisterAsyncTaskPage.RegisterAsyncTask
is also using ThreadPool.
Q5) If I would use Page.RegisterAsyncTaskPage.RegisterAsyncTask
in the OnPreRenderOnPreRender
method do I am sure that in the method RenderContents is only called when all tasks are finished?
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.GetTokenOfCurrentUser(Boolean bWindowsMode, String bstrLogin, String bstrUserKey, String bstrRoles, UInt32 ulRoleCount) at Microsoft.SharePoint.SPSite.InitUserToken(SPRequest request) at Microsoft.SharePoint.SPSite.SPSiteConstructor(SPFarm farm, Guid applicationId, Guid contentDatabaseId, Guid siteId, Guid siteSubscriptionId, SPUrlZone zone, Uri requestUri, String serverRelativeUrl, Boolean hostHeaderIsSiteName, SPUserToken userToken) at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken) at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.GetTokenOfCurrentUser(Boolean bWindowsMode, String bstrLogin, String bstrUserKey, String bstrRoles, UInt32 ulRoleCount) at Microsoft.SharePoint.SPSite.InitUserToken(SPRequest request) at Microsoft.SharePoint.SPSite.SPSiteConstructor(SPFarm farm, Guid applicationId, Guid contentDatabaseId, Guid siteId, Guid siteSubscriptionId, SPUrlZone zone, Uri requestUri, String serverRelativeUrl, Boolean hostHeaderIsSiteName, SPUserToken userToken) at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken) at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
I tried the implementation with Page.RegisterAsyncTaskPage.RegisterAsyncTask
but I am getting following exception:
Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0x80010102 (RPC_E_ATTEMPTED_MULTITHREAD)) at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.SetIPAddr(String bstrIPAddr) at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous) at Microsoft.SharePoint.SPWeb.InitializeSPRequest() at Microsoft.SharePoint.SPWeb.GetList(String strUrl)
Attempted to make calls on more than one thread in single threaded mode. (Exception from HRESULT: 0x80010102 (RPC_E_ATTEMPTED_MULTITHREAD)) at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.SetIPAddr(String bstrIPAddr) at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(SPSite site, String name, Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous) at Microsoft.SharePoint.SPWeb.InitializeSPRequest() at Microsoft.SharePoint.SPWeb.GetList(String strUrl)