Results 1 to 15 of 15

Thread: Asynchronous Programming with Async and Await examples for C# and VB.NET

  1. #1

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Asynchronous Programming with Async and Await examples for C# and VB.NET

    The following site has good examples to get started.

    http://www.wischik.com/lu/AsyncSilve...ncSamples.html

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Clicking the link just brings up a "Must install SilverLard" poster.

  3. #3

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Quote Originally Posted by dilettante View Post
    Clicking the link just brings up a "Must install SilverLard" poster.
    Interesting I clicked on the link via IE-10 and no poster, same with Chrome version 34

  4. #4
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,660

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    works for me, and looks good. Thanks for sharing Kevin!
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Works for me as well, with FireFox, so I have to assume we all already have the SilverLight plugin installed in our browsers, as the site does obviously use SilverLight for its GUI. Since dilettante is forcibly refusing to install the "SilverLard" crap and a whole lot of other bloatware being pushed out there, it is what it is. Caveat Emptor, C'est la vie, ob-la-di, ob-la-da, etc...

  6. #6
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Quote Originally Posted by dilettante View Post
    Clicking the link just brings up a "Must install SilverLard" poster.
    LOL, same thing here ... why am I not surprised?

    Olaf

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Quote Originally Posted by dilettante View Post
    Clicking the link just brings up a "Must install SilverLard" poster.
    Quote Originally Posted by Schmidt View Post
    LOL, same thing here ... why am I not surprised?

    Olaf
    Youtube always asks me to install Flash when I do a re-install of Windows.

    The BIOS always asks me to install an OS whenever I plug in a new hard drive.

    Windows always asks me to install an anti-virus whenever I re-install it.

    Games always ask me to install DirectX after I've installed them.

    Why aren't you guys complaining about those things ?
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Quote Originally Posted by Niya View Post
    Youtube always asks me to install Flash when I do a re-install of Windows.
    Use a different Browser... (e.g. Chrome)

    Quote Originally Posted by Niya View Post
    The BIOS always asks me to install an OS whenever I plug in a new hard drive.
    Tell your BIOS to boot from your USB-Stick then...
    (there's free OSes which support that on a whole lot of different Hardware "out of the Box")

    Quote Originally Posted by Niya View Post
    Windows always asks me to install an anti-virus whenever I re-install it.
    There's OSes which come with a preinstalled anti-virus-suite and a decent firewall...

    Quote Originally Posted by Niya View Post
    Games always ask me to install DirectX after I've installed them.
    There's OSes which can run games out of the box, without requiring
    any DirectX-layer... (e.g. http://en.wikipedia.org/wiki/SteamOS).

    Quote Originally Posted by Niya View Post
    Why aren't you guys complaining about those things ?
    I'm not complaining Niya, only observing (for example the typical ignorance of some
    developers here, who seem not really capable to think outside their little MS-Box).

    Let's have some fun too for a change Niya.

    Olaf

  9. #9
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Thanks for sharing!
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  10. #10
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Quote Originally Posted by Schmidt View Post
    Use a different Browser... (e.g. Chrome)


    Tell your BIOS to boot from your USB-Stick then...
    (there's free OSes which support that on a whole lot of different Hardware "out of the Box")


    There's OSes which come with a preinstalled anti-virus-suite and a decent firewall...


    There's OSes which can run games out of the box, without requiring
    any DirectX-layer... (e.g. http://en.wikipedia.org/wiki/SteamOS).
    I love how you think....except there is a small problem. All the third part software that I use like video converters, BitTorrent clients, media players etc almost always come with Win32 installers. Some might have Linux versions but Win32 is always guaranteed. How do you propose I get around this now ?

    Quote Originally Posted by Schmidt View Post
    I'm not complaining Niya, only observing (for example the typical ignorance of some
    developers here, who seem not really capable to think outside their little MS-Box).
    If MS provides all that I need, why is God's name would I want to look outside ? Even as a developer, there are tools that work on Windows that can target other platforms.

    Quote Originally Posted by Schmidt View Post
    Let's have some fun too for a change Niya.

    Olaf
    Well I'm glad you're entertained
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Quote Originally Posted by Niya View Post
    I love how you think...
    Thank you so very much - assuming therefore, that it's OK to educate you further...

    Quote Originally Posted by Niya View Post
    .except there is a small problem. All the third part software that I use like
    video converters,
    I'm quite sure you already heard of "ffmpeg" for example...
    For (and on) what OS do you think it was developed first?
    http://en.wikipedia.org/wiki/FFmpeg

    Quote Originally Posted by Niya View Post
    BitTorrent clients,
    Ok, next read: http://en.wikipedia.org/wiki/Bram_Cohen
    "...Cohen wrote the first BitTorrent client implementation in Python, and many other programs have since implemented the protocol."

    I'm not exactly sure, when the first (usable) Python-version came out for the Win-platform -
    but I consider 2001 as quite early for a well-working Python (including all the libs)
    on Windows - but that's beside the point IMO - because Python is surely not an
    "MS-invention"...

    Quote Originally Posted by Niya View Post
    ... media players etc
    Ever heard of?
    - Amarok
    - MPlayer
    - Totem
    - VLC
    http://www.dedoimedo.com/computers/media-players.html
    Just to point out a few...

    In my "Linux-phase" I've encountered VLC - and still use this Multiformat-player
    in favour of the MS-one on Windows (no codec-packs to be installed).
    Most good players have their roots in the "free-software-scene" and are
    OpenSource-projects...

    Quote Originally Posted by Niya View Post
    If MS provides all that I need, why is God's name would I want to look outside ?
    Because denying that there exists a huge world outside the MS-Box, is not
    really helping with an objective view on things, Niya.
    Especially when you go on, handing out "advise" to those you consider
    "old fools, using old stuff"...

    Do you really think, that what Developers worldwide are using was primarily invented by MS?
    Just to give you an example - where do you think the MS-Winsock-stack was originally
    derived from? It's basically the (somewhat enhanced) BSD-stack they choose.
    http://en.wikipedia.org/wiki/Winsock

    To an even larger extend, look at Apple - what do you think, Apples MacOS-X was derived from?
    http://en.wikipedia.org/wiki/OS_X

    Quote Originally Posted by Niya View Post
    Even as a developer, there are tools that work on Windows that can target other platforms.
    Again that tight view, where your universe circles around a small moon,
    christened 'MS'...

    I'm more an electronics-guy - where MS (or any MS-tools) are playing only
    a really small role - most of the µControllers programming is done per C -
    most of these small chips have (in their 32Bit-versions) already a small
    Linux running (often in a real-time capable version).

    So, there's a reason, why C is the most popular language currently - whole
    industries depend on it, on it's "stableness" - and the stability of its
    surrounding "support-libs" - there's a requirement (agreement) that every
    engineer considers a "very good idea", in that changes in the language or
    surrounding runtimes need to be applied *very* carefully (timeframes
    of decades need to be considered in most scenarios) - and that's how it
    *should* be (MS was forgetting about that, and one can only hope that
    they change their current practice, especially now that they plan to play
    with the big guys, shifting the company more over to "devices-stuff"...)

    Do you have any clue, how huge that market (and how hard the competition) is?
    E.g. when we list the largest players:
    - Atmel Corporation
    - Freescale Semiconductor, Inc
    - Fujitsu
    - Infineon Technologies
    - Microchip Technology Inc.
    - NXP Semiconductors
    - Renesas Electronics Corporation
    - STMicroelectronics
    - Samsung Electronics Corporation
    - Texas Instruments
    not to forget Apple, but they are so far only acting as an "integrator"
    of the parts the above giants deliver...

    Even when you look at only Texas Instruments for example, which is primarily focusing
    on analogous circuits:
    http://www.ti.com/corp/docs/company/factsheet.shtml

    You will see, that any one of the above plays at least in the same league as MS.

    When you talk about "software development", then you need to come out of the MS-Box,
    when your goal is, to provide an "illuminated audience with *commonly* recognized truths"...

    Olaf

  12. #12
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Very informative post, though I'm already aware that there is a large ecosystem outside MS, that info is interesting nonetheless.

    However, I would need a dozen lifetimes to learn all these different ecosystems. I only have 1 lifetime and it was spent with MS from a very early age. Again, if MS provides all that I've come to need, why then should I waste time starting over with an entirely new ecosystem. I'm all for learning as much as you can but you can spread yourself too thin. Knowing very little of a whole lot really doesn't have much value. There must be a level of specialization.

    I have nothing against somebody who loves to dabble in Linux or Apple or whatever else. But I'm not going to abandon the MS ecosystem simply because of a move by MS that I didn't like. I loved VB6, I really did and I was just as passionate about the move by MS to leave it behind as any of you. You think I don't know how you guys are feeling ? I felt it too. I didn't start using .Net until it was well mature. I started with VS2008 when VS2010 was just released. I'm all the better for it.

    Even so, there are still things that MS does that I don't like. Abandoning XNA for one. The killing of SilverLight for another. While I don't like these decisions, I'm not about to throw away a lifetime spent learning about Windows and all that surrounds it on a stupid emotional whim simply because I feel betrayed which is what these VB.Net hate threads come down to. XNA is gone ? I can always learn DirectX and even if MS doesn't offer a new .Net alternative, I can still learn how to use it in C++, and even so XNA isn't broken, I can still write apps that use it. SilverLight is dead ? I can always learn how to write for Flash if it really comes down to it. Both these options don't require me to abandon Windows. I don't have to adopt an extreme attitude like dilettante who is praying for the demise of Windows at the hands of Android. This is not pragmatic thinking. The just self-righteous posturing.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Frankly, I have no desire to return to the time where there were half a dozen OSes all on an equal footing. Back in that day, I was only interested in games, but with every new game there was always the question of whether or not it was even made for the platform you had. There were some cool mac games, but I had a PC. Some guys in college had a really neat game for the Amiga, but I had a PC. Of course, there were some great games for the PC, too, so it went both ways.

    Except for the problem of ultimate stagnation, it would be better for all developers if there was a single OS. Those of us who are writing internal LOB apps generally have a single ecosystem that we target because that's where we work (and the choice is made for us rather than by us), but those writing end-user apps have to deal with all the fractured ecosystems that are out there. If you are writing lower-level apps, such as creating a language, drivers, or anything like that, then you really get to choose your ecosystem and can do as you like. The rest of us are more harmed than helped by that in the short term. In the long term....everybody is just guessing.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Thumbs up Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    Thought I toss in a simple example that might be of help to those looking to learn. See attachment for VS2012 project.
    See also: Handling Reentrancy in Async Apps (C# and Visual Basic) in regards to alternates to the code in button1

    Code:
    Imports System.Threading
    
    Public Class SimpleExample1
    
        Private AsyncCancelToken As CancellationTokenSource
    
        Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            AsyncCancelToken = New CancellationTokenSource()
    
            Button1.Enabled = False
    
            Try
                Await MyTask()
            Finally
                Button1.Enabled = True
            End Try
    
        End Sub
    
        Public Async Function MyTask() As Task
    
            Dim mProgress As Progress(Of Integer)
            Dim progressTarget As Action(Of Integer) = AddressOf ReportProgress
    
            mProgress = New Progress(Of Integer)(progressTarget)
    
            Await MyProcess(16, 160, mProgress)
    
        End Function
    
        Private Sub ReportProgress(ByVal sender As Integer)
            Label1.Text = "Current: " & sender.ToString
        End Sub
    
        Public Function MyProcess(ByVal width As Integer, ByVal height As Integer, ByVal myProgress As IProgress(Of Integer)) As Task(Of Integer())
    
            Return Task.Run(
                Function()
    
                    Dim result(width * height) As Integer
    
                    For y As Integer = 0 To height - 1
    
                        If AsyncCancelToken.IsCancellationRequested = True Then
                            Exit For
                        End If
    
                        For x As Integer = 0 To width - 1
                            Thread.Sleep(10)
                        Next
    
                        If Not myProgress Is Nothing Then
                            myProgress.Report(y)
                        End If
    
                    Next
    
                    Return result
    
                End Function,
                AsyncCancelToken.Token
            )
    
        End Function
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            AsyncCancelToken.Cancel()
        End Sub
    
        Private Sub SimpleExample1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Label1.Text = ""
        End Sub
    End Class
    Attached Files Attached Files

  15. #15
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: Asynchronous Programming with Async and Await examples for C# and VB.NET

    The objection to 'silverlight' is that the WHOLE page uses it; not just a small app, video, etc.

    It's an example of not understanding the consumer requirements. While those that have Siverlight activate automatically (<snort!>) will probably have no issues, my question is, 'why is this a silverlight app, for a trivial, informational, page?'
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width