some problems with async await
hey guys before anything sorry for my bad english but here's my problems:
1. how can i add an item to a listbox in an async event method of a bindinglist's listchanged event.
2. whe i have one async method in my code there is no problems but when i have 2 or more async methods no matter wich one is running or one of them is running my app thows an exeption in delegate class and usually it's "parameter is not valid" and i have one guess and that is when in a try catch block some error happens it show me "parameter not valid" exeption in delegate class. i will be appreciated if you guys can help me
39 Replies
I can guide you
thank you so much
so what should i do?
First show me your problem with code
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/ i have bindinglist named list and this method is it's listchanged event
and i add content to my binding list in method
and method is called like this in a button's click event
threading exception?
this is for the listbox and it doesn't throw any exception neither it doesn't update the listbox
sooo
thst's probably because it's throwing an exception
set a breakpoint on
var x
also on the await
it didn't worked
let me send you the exception
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
inner exception Parameter is not valid
and it throws the exception in delegate class and the final line of the method
what's the inner exception?
Parameter is not valid
where?
in the last line of this method in the delegate class
no
the inner exception
This exception was originally thrown at this call stack:
System.Drawing.Bitmap.Bitmap(System.IO.Stream)
Kambiznet_bot.Bot.BotForm.TakeScreenshot(string, string) in BotForm.cs
Kambiznet_bot.Bot.BotForm.CaptchaSolver(Microsoft.ML.ITransformer, Microsoft.ML.MLContext, string) in BotForm.cs
Kambiznet_bot.Bot.BotForm.RegisterPerson(Kambiznet_bot.Models.Person) in BotForm.cs
Kambiznet_bot.Bot.BotForm.StartBot(System.Collections.Generic.List<Kambiznet_bot.Models.Person>) in BotForm.cs
Kambiznet_bot.Bot.BotForm.button1_Click.AnonymousMethod__20_0() in BotForm.cs
System.Threading.Tasks.Task.Execute() in Task.cs
Kambiznet_bot.Bot.BotForm.button1_Click(object, System.EventArgs) in BotForm.cs
where
is being called
Bitmap Constructor (System.Drawing)
Initializes a new instance of the Bitmap class.
so,
bytes
appears to be invalid data
what's in it?
i used bytes only in this part
okay
which one is
bytes
?what do you mean exactly?
using (var ms = MemoryStream(bytes))
As in what are you passing to the MemoryStreamnothing
should i pass the byte array to the memorystream?
I was quoting the code you posted...
oh ok i see
And what's Image?
it extracts an image from a website and turn it into byte array and then to Image
Have you checked what it's actually returning when it tries to get the image?
in G method?
Yeah, have you debugged all the way through to see its doing what you think it's doing?
to be honest i have no idea because i copied this part of code
but i cheaked it before and i didn't understand what it's doing
I mean I would suggest you need to set some breakpoints and follow it through step by step, see if things are actually getting set correctly/try and understand the code too
ok
it returns a string with some none sense content
but it will correctly save and crop images
is your base64 string actually a valid image? try pasting it in here https://base64.guru/converter/decode/image
i cheaked it in that website and it was valid