fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Availability of 'Concurrency' within .NET !?

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3062

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Robert, Chris and all Forum guys,

today I was doing some learning about 'GO' the language, and it made me wonder just what facilities there are in the .NET modern Framework for handling (writing) concurrency into our code.

According to the YouTube guy there is a subtle but major difference between parallel coding and Concurrency.

Have any of you guys tried any GO coding as yet ?

TIA,
Phil.

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3069

  Chris's Avatar Chris Offline Posts: 1164
Hi Phil,

A quick search shows this:

docs.microsoft.com/en-us/dotnet/standard...sing-and-concurrency
msdn.microsoft.com/en-us/library/system....rrent(v=vs.110).aspx

sounds very interesting, but to be honest I have not used those features myself (yet).

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3070

  wriedmann's Avatar wriedmann Away Posts: 1567
Hi Chris, hi Phil,

some time ago I wrote a sample for asyncron processes:

https://www.riedmann.it/download/AsyncApp.zip

It is a small WPF application that starts a simple asyncron process. And yes, it uses a BlockingCollection object from the System.Collections.Concurrent namespace.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3071

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Thanks Wolfgang,

I will look into this as Meinhard wants me to cover in some way Blocking and Asynchronicity with my session on "Arrays to Collections" at Cologne 2018.

Is Concurrency in .NET what we have been calling 'Async' coding ?

Speak soon,
Phil.
Wales, UK.

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3072

  wriedmann's Avatar wriedmann Away Posts: 1567
Hi Phil,

at least the two links Chris has posted lead to this functionality.
I had looked at them and remembered that I hat written something a few months ago (as a test for myself).
In WPF unfortunately you need something like this otherwise your GUI will freeze until the process terminates. It is not like WinForms or VO GUI where you can call a function to give processing to the GUI ( ApplicationExec( EXECWHILEVENT ) in VO per example.

If you are populating a DataGrid from a collection that is refreshed from a background process there is another caveat: sometimes the DataGrid will give a runtime error that the number of elements is different from the effective collection size.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3073

  NickFriend's Avatar NickFriend Offline Posts: 193

Wolfgang Riedmann wrote: Hi Phil,
If you are populating a DataGrid from a collection that is refreshed from a background process there is another caveat: sometimes the DataGrid will give a runtime error that the number of elements is different from the effective collection size.


Hi Wolfgang,

This sounds like an ObservableCollection... there's a basic rule that you mustn't use another thread to add/remove items from ObservableCollections that are used on the UI thread. It took me a while (and a lot of runtime errors!) to realise this.

It's not really a problem though... typical scenario is refreshing data from a database or adding a newly created item. So the slow bit is getting data from the db - run that asynchronously, then simply apply the update to the collection on the UI thread after the awaited method has completed.

I believe there are ways now to handle OCs from other threads, but I haven't investigated.

Nick

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3074

  wriedmann's Avatar wriedmann Away Posts: 1567
Hi Nick,

This sounds like an ObservableCollection... there's a basic rule that you mustn't use another thread to add/remove items from ObservableCollections that are used on the UI thread. It took me a while (and a lot of runtime errors!) to realise this.


exactly. In my case it is a server monitor that requests pages from a remote server and displays the times on a DataGrid.

I suspected something like this, but had not the time to investigate further.

I have planned to do this in a background service process and use the GUI application only to display the data from the local SQLite database - but unfortunately I'm short on time all the time <g>.

This is the exact error message:
This exception was thrown because the generator for control 'rdm.MVVMControls.MVVMDataGrid Items.Count:18' with name 'MonitorData' has received sequence of CollectionChanged events that do not agree with the current state of the Items collection.  The following differences were detected:
  Accumulated count 17 is different from actual count 18.  [Accumulated count is (Count at last Reset + #Adds - #Removes since last Reset).]

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3075

  wriedmann's Avatar wriedmann Away Posts: 1567
Hi Nick,

a quick search on Google gave this for example:

https://stackoverflow.com/questions/23108045/how-to-make-observablecollection-thread-safe

I like the fact that I'm can use all the tips and recipes from the large C# community!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3076

  NickFriend's Avatar NickFriend Offline Posts: 193
Hi Wolfgang,

I'd be a bit wary of solutions like that. I found the best thing was to simply work within the basic design paramters and refactor the code to avoid updating collections on the background thread. If you move the slow processes into asynchronous methods, then call those with await from your UI thread, when the awaited method returns you can safely update your ObservableCollection.

I now do this everywhere, and the UI is 100% smooth and we get no updating errors.

There are loads of modified observablecollection classes, and I've tried several at one time or another, but they all have issues. The other classic is getting existing objects in a collection to update - there are subclasses that supposedly handle this, but in the end it's best to work with WPFs design logic and make sure you implement INotifyPropertyChanged properly on the objects in the collection.

That's my experience at least.

Nick

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3077

  wriedmann's Avatar wriedmann Away Posts: 1567
Hi Nick,

thank you very much for your precious advice!

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3079

  Phil Hepburn's Avatar Topic Author Phil Hepburn Offline Posts: 742
Hi Nick and Wolfgang,

An interesting discussion indeed :blink:

It would seem to me Nick that you have talked your way into helping me come up with a suitable simple-as-possible X# example for the Cologne conference at the end of April :whistle:

I will get back to you later on this, and we will do something all 'your way'.

At the moment I am digging deep into .NET System.Array class objects - something I should have done ages back.

Regards to all,
Phil.

P.S. - so is this 'Concurrency' ? No body answered my direct simple question.

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3081

  NickFriend's Avatar NickFriend Offline Posts: 193
I should have learnt by now to keep my mouth shut :unsure:

I did a presentation on async programming at DevShare a few years back (2013 I think)... for starters there should a be a fairly detailed presentation in the notes.

Nick

Please Log in or Create an account to join the conversation.

Availability of 'Concurrency' within .NET !? 1 year 7 months ago #3082

  wriedmann's Avatar wriedmann Away Posts: 1567
Hi Nick,

your contribution was very helpful - not only for me but also for other, I think.

So please continue to write your opinion.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
This email address is being protected from spambots. You need JavaScript enabled to view it.
www.riedmann.it - docs.xsharp.it

Please Log in or Create an account to join the conversation.

  • Page:
  • 1