Reputation: 11601
Is there any way to working with Clipboard
in ASP.NET
, in Server-side
?
I want to push something in Clipboard
& fetch it.
EXTRA INFO:
I had some search and found out, the solution is working with Thread
. but I'm looking for another way, if is there another way.
UPDATE: Please answer to following questions:
For example:
Option 1:
void myMethod(object i){
// put something on clipboard and get that
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
for(int i=0; i<100; i++){
Thread t = new Thread(myMethod);
t.Start(i);
}
}
Option 2:
void myMethod(){
for(int i=0; i<100; i++){
// put something on clipboard and get that
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Thread t = new Thread(myMethod);
t.Start();
}
Which one is correct?
Upvotes: 2
Views: 1757
Reputation: 5144
This is how you do it:
public static void PdfToJpg()
{
var Thread = new Thread(PdfToJpgThread);
Thread.SetApartmentState(ApartmentState.STA);
Thread.Start(); // You can pass your custom data through Start if you need
}
private static readonly object PdfToJpgLock = new object();
private static void PdfToJpgThread(object Data)
{
lock (PdfToJpgLock)
{
for (int i = 0; i < count; i++)
{
// Call to Acrobat CopyToClipboard
// ...
Clipboard.GetImage().Save(outputPath, ImageFormat.Jpeg);
Clipboard.Clear();
// ...
}
}
}
For each button click, just call PdfToJpg()
and you are done.
Upvotes: 1