0

My IDE is always opening up and giving me this message:

try
{
   await Task.Delay(1000, App.tokenSource2.Token);
}
catch (TaskCanceledException ex) { ex = null; }

The variable ex is declared but never used.

I would like to avoid being the message. Any suggestions?

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • You can disable the pragma warning - https://stackoverflow.com/questions/3820985/suppressing-is-never-used-and-is-never-assigned-to-warnings-in-c-sharp – ArcX Aug 29 '17 at 06:51

1 Answers1

4

Just dont specify any variable if you are not planning to use it:

try
{
   await Task.Delay(1000, App.tokenSource2.Token);
}
catch (TaskCanceledException) { ... }
3615
  • 3,787
  • 3
  • 20
  • 35