Hi, I have an application that at a given moment launches a Thread, within that Thread a user control is called where an image is placed on a button within the user control.
The user control has a list of Tuples made up of a TextBox and a Button, in order to know which Button is associated with each TextBox.
I have the problem when I try to search within that list of tuples for which button to put the image on.
I put the code used:
The part where the Thread is created to run in the background:
Thread preparaPDF = new Thread(() => lanzaComprobacionPDFIndividual(idActual));
preparaPDF.IsBackground = true;
preparaPDF.Start();
Within lanceComprobacionPDFIndividual, the viewerPDF user control is called:
visorPDF.anadeFichero(listaIDs[idActual], ficG, true);
and the function where it gives me the error is in anadeFichero
public void anadeFichero(string id, string ruta, bool bueno)
{
try
{
Button b = (Button)listaRelacionada.Find(x => (x.Item1 as TextBox).Text == id).Item2;
if (b != null)
{
b.Tag = ruta;
habilitaBoton hab = new habilitaBoton(enableBoton);
b.Invoke(hab, b, bueno);
}
}
catch (Exception ex)
{ }
}
In fact I have put a try catch in case it throws an exception but it doesn't throw anything, it just stops there.
I find this error very strange since as seen in listRelated there are values.
Here is a screenshot of how it looks in debug.
Thanks for the help.
Hello, I have managed to solve this issue in the following way: Instead of being with a background process, thread or task watching when the pdf is generated, I do it using a timer that checks every 500 milliseconds if the file has been generated, a Once the file has been found, to modify the graphical interface of the user control I have adapted a class that I have found in English Stackoverflow, which I put below:
Then, instead of looking for the button in the list of controls where it is and creating a copy of it, I use it directly as follows:
being routeInCurso the location of the pdf, resultInCurso if the result of the test has been good or not and bit the bitmap that is passed to the button.
Thank you all so much for the help and ideas.