Category Archives: Multithread

Multithread

VS2010 Concurrency Visualizer for Web projects?

Is there a way to use the VS2010 Concurrency Visualizer for a web project?

When I have a web project and select "Analyze"/"Launch Performance Wizard…"/"Concurrency"/"Visualize the behavior of a multithreaded application" and then click "Next", the performance wizard says I do not have a "launchable project available to profile
in teh current solution".  So, how am I supposed to profile my multi-threading for a web project? I’d like to know if I’m accomplishing anything by going multi-threaded (.net 4.0) using Tasks….

TIA,

VS2010 Professional .NET 4.0 Remote Debugging ASP Website Project

Trying to remote debug ASP website from VS2010 Pro to Windows Server 2003 machine.  Specifically, trying to debug a Web Service, but breakpoint says, "The breakpoint will not currently be hit. No symbols have been loaded for this document."  This happens
for all compiled code though.  I have read this is due to missing PDB files and the work around is to manually copy them, as noted
here.  Problem is, I cannot find any PDB files for my project, except referenced libraries, which I can remote debug.

Verified

  • web.config has <compilation debug="true">
  • Debugger is attached to wewp.exe process on remote server
  • Installed VS2010 remote debugger from DVD (as I can remote debug referenced libraries)

This is beyond frustrating.  I migrated my code from VS2008 .Net3.5 to VS2010 .Net4.0 to take advantage of the inherent multithreading framework.  Debugging works when using local host and was stable until deployment to test server.

Thanks in advance,

Anthony

Anthony, I’m sure no expert, but I do know that the symbol files (PDB’s) are only generated for a "Debug" build. Also, you will need this line in your web.config

<compilation debug="true">

and on the "web" tab of the project properties, make sure that "ASP.Net" is checked down on the bottom of the page in the "Debuggers" section.

I’m still trying to figure this stuff out myself, but the above should help you since nobody else seems too interested in helping you out on this one.

I’ll look into the "Debug" build, but as stated I already have <compliation debug="true"> tag.  Everything else is as you mentioned.

Thanks for the reply.  At least it wasn’t completely disregarded.

 

Anthony 

[RESOLVED]Web Workers Timeouts and Intervals (How to set)

Hello,

I’m trying to get to grips with web workers and how to set timeouts and intervals.
I can’t seem to find any straight forward documentation to support these features.

I’ve seen documentation which involves using window.setinterval, but it’s unclear if that’s in the context of a web worker (My understanding is that web workers are not allowed to have anything to do with the UI).

Can anyone please give me a simple example of how to create a web worker, set a timeout, set an interval and clear a time out and clear an interval please.

Links to any documentation would also be appreciated.

hello,

The article in the following link gives a sumary of web worker, please check it and see if it helps,

http://blogs.msdn.com/b/davrous/archive/2011/07/15/introduction-to-the-html5-web-workers-the-javascript-multithreading-approach.aspx

HTML5 – Multithreading in JavaScript with Web Workers

http://xebee.xebia.in/2010/11/02/multithreading-in-javascript-with-web-workers/

thanks.

Thanks for the links, they helped.

Below is what I’ve got on the html page.

<script type="text/javascript">
        var worker = new Worker("Scripts/webworkertest.js");

        worker.onmessage = function (event) {
            alert("Reply: " + event.data);
        }

        function goAndDoSomething() {
            worker.postMessage("some message");
        }

        setInterval(goAndDoSomething, "5000");
    </script>

And below is what I’ve got in the javascript file (i.e. the webworker itself):

this.onmessage = function (event) {
doStuff();
}

function doStuff() {
postMessage("sent from worker");
}

So just to explain (So you can correct anything I’ve gotten wrong). the set/clear interval and set/cleartimeout is created on the webpage itself, NOT in the web worker (Which I understand it does have access to, but why would you need it? Just to time work
within the worker functions?).

What I’m not fully clear on is why I’m doing worker.onmessage in the html page AND the javascript file.
I’m guessing that when I assign a function to worker.onmessage on the html page, I’m listening for messages from the web worker, and when I  assign a function to this.onmessage within the javascript file I’m listening for messages from the
html page.
Is that right?

Thanks. 

Hi,

stevex33

So just to explain (So you can correct anything I’ve gotten wrong). the set/clear interval and set/cleartimeout is created on the webpage itself, NOT in the web worker (Which I understand it does have access to, but why would you need it? Just to time work
within the worker functions?).

Time elapse functions (set/clear interval and set/clear timeout)
 are different than Async functions/objects.
 
Time elapse functions invokes passed functions after specified time (may blocks UI)
Where as, Async objects invokes functions (without blocking UI) and informs (via event) after complete.

stevex33

I’m guessing that when I assign a function to worker.onmessage on the html page, I’m listening for messages from the web worker, and when I  assign a function to this.onmessage within the javascript file I’m listening for messages from the
html page.
Is that right?

yes that right.

[RESOLVED]VB 2005 – Export to Excel Threading

I am able to export data to excel using VB 2005. The problem I’m having is while the export is running, it holds the application hostage so you can’t click any buttons such as CANCEL to cancel the export.

Is there a way to export the data using a new thread so my program isn’t held hostage?

 Hi,

Y donot U try Exporting Excel Directly From Sqlserver:-

=1 method Using sp_makewebtask=======

EXEC sp_makewebtask
    @outputfile = ‘d:testing.xls’,
    @query = ‘Select * from Database_name..SQLServerTable’,
    @colheaders =1,
    @FixedFont=0,@lastupdated=0,@resultstitle=’Testing details’

=====================================

==============2======================

 Export data to existing EXCEL file from SQL Server table

insert into OPENROWSET(‘Microsoft.Jet.OLEDB.4.0′,
    ‘Excel 8.0;Database=D:testing.xls;’,
    ‘SELECT * FROM [SheetName$]‘) select * from SQLServerTable
====================================

======3=============================

Export data from Excel to new SQL Server table

select *
into SQLServerTable FROM OPENROWSET(‘Microsoft.Jet.OLEDB.4.0′,
    ‘Excel 8.0;Database=D:testing.xls;HDR=YES’,
    ‘SELECT * FROM [Sheet1$]‘)

====================================

or

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Hope it helps

This has been resolved using multithreading.

Could you post your solution please?

[RESOLVED]Multithreading in webservices

I am using webservices in my application,but i am facing the following performance(huge time tsking) problem. Working on the travel domain application.on searching the travel services. I am searching Flight,Hotel,Car and Forex services,

Flight service contains 3 webservices 1.galileo,Ezeego and makemy trip webservices(consumes 15 seconds to get response)

Hotel service contains 3 webservices 1.galileo,Hotelspro and Bookings.com webservices(consumes 25 seconds to get response)

Car service contains 3 webservices 1.cartrwaler webservices(consumes 15 seconds to get response)

and totally it will take 60 seconds to get the whole response from all services.

I am using Asp.net C# in a sequential way i am hitting the api. Can anyone please suggest me how can i reduce the performance time(5 sec) by using .net technology.

I think Multithreading is the way to do ,but in multithreading which concept i have to use,please guilde me.

Hi,

First I completely agree with Mikesdotnetting and the article he suggested is excellent. No doubt you need to implement Asynchronous Calls to WebServices.

dharmeshsharma

Flight service contains 3 webservices 1.galileo,Ezeego and makemy trip webservices(consumes 15 seconds to get response)

Hotel service contains 3 webservices 1.galileo,Hotelspro and Bookings.com webservices(consumes 25 seconds to get response)

Car service contains 3 webservices 1.cartrwaler webservices(consumes 15 seconds to get response)

and totally it will take 60 seconds to get the whole response from all services.

But, I am worried the amount of time is still very high. Along with that I suggest use of JSON and AJAX. It is very important to do that as it will drastically reduce the time and aid in the implementation. For example if  AJAX is used , partial page updates
can be implemented that will effect just the part of the page or the Update Panel which is calling the Webservice not the entire page. So , in this way all the three webservices can be updated or refreshed independently.

Understanding Partial Page Updates with ASP.NET AJAX

http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-partial-page-updates-with-asp-net-ajax

Addition to that.

The Second Piece of the Asynchronous Solution: Asynchronous PreRequestHandler Execution -
http://msdn.microsoft.com/en-us/library/aa480507.aspx

If Asynchronous PreRequestHandler Execution is implemented the webservice calls will speed up by three times. 

Hope it helps!

Best Regards!

 

Hi Sam,

Sorry For late Response

But APis is Third party developed we just access,

for Flight we have 3 APis diff companys so we trying to do with Multithreading as Mikesdotnetting show me link its , but All 3 Apis on diff technologys like one on asmx, second one on XML, third one on JSP xml

so we have to call diff -diff method and technic to do this

whtas you Suggest for this

Thanks

Controlling iTunes with ASP.NET

I’ve been trying to control iTunes with ASP.NET with varying levels of success, but none that fits my situation exactly. I’ve looked around the web and tried all of the provided solutions without much luck. I’ve tried using many different iTunes COM libraries
(even the one that’s on Apple’s developer website), still no luck. The issue is, when I’m using Visual Studio’s development server to create an instance of the iTunes COM object – iTunesApp – it works perfectly and allows me to control iTunes. This also works
perfectly in a Console and WinForms app. But as soon as I switch it to use the IIS server, nothing seems to work. I need it to run as a website under ASP.NET so it can receive requests from other devices. It throws the following error on creation of a new
instance of the iTunesApp class: 

Retrieving the COM class factory for component with CLSID {DC0C2640-1415-4644-875C-6F4D769839BA} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

First I was using the iTunes.Interop.dll file that is used in many of the projects around the web. I tried many times without luck and then tried registering the DLL, that threw an error about not finding an entry point into the DLL. So then I found that you have to give permission to the Application Pool Identity that the web app is running under to acces and execute the DCOM service in Windows Component Services. I did that, and also gave access to Everyone, still nothing. Then I tried using the COM library that is installed by iTunes (when you go to Add Reference, instead of browsing to the DLL file, I went under COM tab and selected iTunes Type Library), no luck. I suspect that when I gave permission to the Windows DCOM component, I gave permission to the installed iTunes COM library since Windows recognized that as installed (and I couldn’t register the original iTunes.Interop.dll – Windows wouldn’t know it was there).

Both, the installed iTunes Type Library and the iTunes.Interop.dll file, gave me the same aforementioned error. Strangely, the CLSID in the error (DC0C2640-1415-4644-875C-6F4D769839BA) doesn’t match iTunes’s “Application ID”, as it is called in Component ServicesDCOMiTunesProperties window, which is F98206B5-F052-4965-9FA0-85F61BC3C19D. My suspicion is that I’m not giving permission to the correct DCOM component in Windows. I searched my registry for the CLSID in the error and it returns no results, so I concluded that it’s not the Application ID of any of the DCOM components (all the Application ID’s are under ComputerHKEY_CLASSES_ROOTWow6432NodeAppID – didn’t find it in there either). But since it’s the CLSID in the error, it must be referenced to somewhere, I just couldn’t find it anywhere. Searching for either ID on Google isn’t helpful either because they both return search results that include iTunes, but none specific enough to the problem. 

I even tried the multithreaded approach. Since COM libraries run in STA model and web servers run in MTA, one of the solutions I found suggested to convert the server’s thread execution model to STA and then call the COM library. This didn’t work either. I have duplicated this problem on 2 computers running completely independent, and on both computers the Visual Studio Development Server can run it but IIS cannot. 

Here’s the code I’m using (without the multithreading):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTunesLib;


namespace NewASPXNetduino2
{
	public partial class _Default : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			Response.Write(WindowsIdentity.GetCurrent().Name + "n");

			var iTunes = new iTunesApp();

			iTunes.Play();
		}
	}
}

The error is throw at the line: var iTunes = new iTunesApp();

If the multithreaded code would help, I can post that too. I’m pretty much directionless at this point and would appreciate any help in any capacity. Thanks.

Hi

Here is a good article about how to use ItunesLib

http://blogs.msdn.com/b/noahc/archive/2006/07/06/automating-itunes-with-c-in-net.aspx

hope it hlepful.

Yeah I’ve already seen that article. Like I said, I can get it to work in a console application, but it fails to work under IIS. Believe me, I’ve looked everywhere on the web for about 2 weeks and visited almost every link about this topic and tried every
technique, that’s why I’ve come to the forums, because none of these links seem to help me in this exact situation. Running it under a Console App OR the Visual Studio Web Server works, but it doesn’t work when I run it as an ASP.NET application under IIS.
Thanks anyways, I know this is not a very common issue.

[RESOLVED]Debug Threads

Hi,

I have an application where there are multiple tasks distributed across different thread.

The threads are started on click of a button click using Start() method of Thread class.

One of the methods in the class is assigned to a thread. 

When I do the button click that time I am able to debug the method, but then after even if I keep a breakpoint in the method, the command is not getting to the breakpoint. 

Please help me how to do debugging in multi threaded application.

Hi

Moreover, you could refer this about the specific procedures in
Walkthrough: Debugging a Multithreaded Application
.

Visual Studio 2012 provides an improved Threads window and other user interface improvements to make it easier to debug

multithreaded applications.

hope it helps

Regards

[RESOLVED]problem with debugging

hi everybody

I have a problem with debugging my MVC project. I insert a breakpoint to debug and then when i use F10 to trace each line , all lines are executed 2 or 3 times and i have to push F10 several times to go to the next line !

does anybody see something like this !

no such problem. Check another  keyboard.

Actually our team contains 8 programmer and all of us had this problem so it is not a keyboard problem. our solution contains 5 project which one is mvc and others are class library . this problem happens when controller im vmc try to access a function in
other projects.

dew_sh36

our team contains 8 programmer and all of us had this problem

dew_sh36

 I insert a breakpoint to debug and then when i use F10 to trace each line , all lines are executed 2 or 3 times

Wow. Quite a problem.  If you click on the menus, Debug=>Step Over, the problem occurs also?

Yes ,of course . even when i use menus, Debug=>Step Over it happens !

Hi,

is this occuring only in one specific project? Or it also happens when you create a new solution + project from scratch and try it then? If not then it’s something likely with some setting in your project. If yes then it’s likely due to a setting in your
Visual Studio.

Grz, Kris.

hi,

I found something : when i use breakpoint and F10 for each breakpoint, it appears that he executes twice the code. On the breakpoint it says:

"The process  or thread has changed since the last  step. " and when it comes to update the database it says:

"ChangeConflictException was unhandled by user code. Row not found or changed.".

but i dont know what couse this multithreading !

[RESOLVED]make AJAX calls parallel,

Hi all,

I need your help about two web method to Read content  of text file .

I have two web method,:

  • writeFile: To execute SSIS Package (write ine in text File)
  • ReadFile (Read Content Parallel of the same file)

My problem is that in above scenario, all the ajax calls are going serially. That is, after writeFile call is complete ReadFile starts,

First Ajax call(writeFile) is taking roughly around 25 sec to get the data, which makes the First Ajax call(ReadFile) wait  around 25 sec.

My question is: How can I make these calls parallel, so that I start getting all this data parallely ?

Thanks in advance.

function WriteFile(fileName)
{
$.ajax({
type:"post",
url :"Fichier.aspx/WriteFile",
Data:{fileName:’"+fileName +’",
….
});
var lineNumber=0;
ReadFile(fileName);

}

function ReadFile(fileName)
{
$.ajax({
type:"post",
url :"Fichier.aspx/ReadFile",
Data:{fileName:’"+fileName +’",lineNumber:"+lineNumber+"}",

success:function(msg){
lineNumber=lineNumber+1;
setTime(ReadFile,5000);
$("<p>"+msg.d+"</p>").appendTo(‘#uppendTo(‘#mytxtfile’);
});
ReadFile(fileName);

}
});

}

use fiddler, you should see the browser make the two calls without waiting. most likely your server code uses session, which queues request to the same session. remove ression from the server code, and the ajax calls will be parallel.

Can you give me more info? please?i don’t use multithreading in webmethode, just one thread

Any ideas please??

i would suggest you try using jQuery.when (deferreds):

$.when( $.ajax("/req1"), $.ajax("/req2"), $.ajax("/req3") ).then(function(resp1, resp2, resp3){
    // plot graph using data from resp1, resp2 & resp3 
});

callback function only called when all 3 ajax calls are completed.

please refer to the links for details:

Tracking/ joining parallel AJAX requests with jQuery

http://www.mattlunn.me.uk/blog/2014/01/tracking-joining-parallel-ajax-requests-with-jquery/

http://css-tricks.com/multiple-simultaneous-ajax-requests-one-callback-jquery/

Hope it helps you.

NoMoneyNojob

Can you give me more info? please?i don’t use multithreading in webmethode, just one thread

asp.net uses a thread per request, so jquery can do concurrent ajax requests. but if you use session, asp.net will only process in order as two request to the same session are not allowed. so you be sure the page hosting the webmethods as session turned
off.

 

[RESOLVED]Can anyone give me an understandable example of using ConcurrentDitionary

Can anyone give me an understandable example of using ConcurrentDitionary?

I appreciate the suggestion. I have seen that previously. I’m hoping for a real world example of the use of it.

Hi ,

 

Jackxxx

I appreciate the suggestion. I have seen that previously. I’m hoping for a real world example of the use of it.

If you are looking for like advantages and Best practices on where to use ConcurrentDitionary.

One of the goals in concurrent programming is to reduce contention. Contention is created when two (or more) threads contend for a shared resource. The performance of synchronization mechanisms can vary considerably between contended and uncontended
cases.

So how does ConcurrentDictionary do better?

  • Reading from the dictionary (using TryGetValue) is completely
    lock-free. It uses memory barriers to prevent corrupted memory reads.
  • Enumerating the dictionary (using GetEnumerator) is also
    lock-free, but does not guarantee a “moment in time” snapshot of the dictionary (i.e. the enumeration may change after calling
    GetEnumerator, but we usually wouldn’t care about that in multithreaded environments).
  • Writing to the dictionary uses multiple lock objects (also referred to as
    fine-grained locking) which considerably reduces the chance of contention.

    • By default, the dictionary creates 4 times the processor count of lock objects (in .NET 4.5 this number also grows dynamically as the dictionary fills up – another scale up benefit).
    • You can also specify a fixed concurrency level (i.e. number of locks) via a constructor parameter (but normally you shouldn’t as you lose the dynamic growing).
    • Each object is assigned a lock according to its hash code. Usually a single lock object is responsible for several buckets.

Source Article:

http://arbel.net/2013/02/03/best-practices-for-using-concurrentdictionary/

Also refer to the following:

http://dotnetcodr.com/2014/01/15/thread-safe-collections-in-net-concurrentdictionary/

http://www.codeproject.com/Articles/548406/Dictionary-plus-Locking-versus-ConcurrentDictionar

Hope the above links gives you a better undestanding about when and how to use ConcurrentDitionary.

Best Regards!