0

I have a Button on a UserControl.

I'm marking the UserControl's Click event handler for the Button as Async, so I can run an asynchronous method from inside it. I have to do it this way, otherwise the UI blocks and a ToolStripLabel on the Form doesn't get updated before the SchedulerNode.Load() method is called.

Visual Studio isn't liking it very much, but the warning it's returning seems both incorrect and misapplied.

Here's the code:

enter image description here

And here's the warning:

enter image description here

Note that VS indicates the correct line number but the wrong file (the designer code). And according to the warning I should make it an Async Sub... but it already is.

It looks like this may be a bug in the IDE. Can anyone else confirm?

InteXX
  • 6,135
  • 6
  • 43
  • 80
  • 2
    Have you checked the designer file? Maybe there is an async function there, too? – Nico Schertler Feb 15 '15 at 09:18
  • @NicoSchertler - Good point, I hadn't. Nevertheless, nothing `Async` is there--the only methods are the standard `InitializeComponent()` and `Dispose()` entries. Can you reproduce it? – InteXX Feb 15 '15 at 23:41
  • 1
    I'm coming from a C# perspective so shouldn't you always return a Task? Void asyncs are supposed to be avoided (no pun). Try making it a function that returns Task. – Crowcoder Feb 16 '15 at 00:32
  • @Crowcoder: VB `Sub` = C# `void` (but you knew that). Right, it's best to steer away from `Async Sub`... *except* for event handlers. [This](http://stackoverflow.com/a/19415703/722393) from our resident Async/Await expert, Stephen Cleary. That said, I did try returning a `Task`; the same IDE warning persists. I'm just about ready to chalk it up as a bug. What happens in your case? Do you get the warning? – InteXX Feb 16 '15 at 01:56
  • @InteXX: What's in the designer file at line 99? – Stephen Cleary Feb 18 '15 at 13:24
  • @StephenCleary: I modified the main code, so it's reporting line 97 now. Here's the [designer file](http://1drv.ms/1DDekCy). This sure looks like an IDE bug to me. Next up... try to reproduce it in a brand-new project. – InteXX Feb 18 '15 at 21:22
  • @StephenCleary: OK, I can reproduce it in a new clean project. I'm just about to report this as a VB bug (doesn't occur in C#). I haven't tried it in VS 2015 yet; I haven't installed that and probably won't until RTM. If anyone who's got 2015 already installed could try it in VB it'd help. – InteXX Feb 18 '15 at 21:49

0 Answers0