Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 156661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:22:00+00:00 2026-05-11T10:22:00+00:00

I’m trying to create a form that will animate something while processing a particular

  • 0

I’m trying to create a form that will animate something while processing a particular task (passed as a delegate to the constructor). It’s working fine, but the problem I’m having is that I can’t instantiate a copy of my generic class if the particular method that I want to perform has a return type of void.

I understand that this is by design and all, but I’m wondering if there is a known workaround for situations like this.

If it helps at all my windows form looks like so (trimmed for brevity):

public partial class operatingWindow<T> : Form {     public delegate T Operation();     private Operation m_Operation;      private T m_ReturnValue;     public T ValueReturned { get { return m_ReturnValue; } }      public operatingWindow(Operation operation) { /*...*/ } } 

And I call it like:

operatingWindow<int> processing = new operatingWindow<int>(new operatingWindow<int>.Operation(this.doStuff)); processing.ShowDialog();  // ...  private int doStuff() {     Thread.Sleep(3000);      return 0; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:22:00+00:00Added an answer on May 11, 2026 at 10:22 am

    I would rethink your design slightly.

    If you implemented the processing in a base class, you could subclass it with 2 alternatives that would be nearly interchangable.

    The first could be like yours, where it takes an Operation that returns a value. (I would rework this to use Func<T> instead of having your own delegate type, though.

    The second could just take a simple Action and not provide a return value. Both could use the same animation/display/etc. routines, but provide a different way of working. You could also pass this off to other methods using the base class, which would provide a lot of flexibility.

    With this approach, you could call this like:

    private void DoSleep() {     Thread.CurrentThread.Sleep(5000); } private int ReturnSleep() {     Thread.CurrentThread.Sleep(5000);     return 5000; } ... {     var actionWindow = new OperatingWindowAction(this.DoSleep);     actionWindow.Execute();     var funcWindow = new OperatingWindowFunc<int>(this.ReturnSleep);     funcWindow.Execute();     int result = funcWindow.Result; } 

    This would look something like:

    public abstract partial class OperatingWindowBase : Form {     public void Execute()     {         // call this.OnExecute(); asyncronously so you can animate     }     protected abstract void OnExecute(); }  public class OperatingWindowFunc<T> : OperatingWindowBase {     Func<T> operation;     public T Result { get; private set; }     public OperatingWindowFunc<T>(Func<T> operation)     {         this.operation = operation;     }     protected override OnExecute()     {         this.Result = operation();     } }  public class OperatingWindowAction {     Action operation;     public OperatingWindow(Action operation)     {         this.operation = operation;     }     protected override OnExecute()     {         operation();     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ran the script on my local server and got… May 12, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer MIGRATING DATA FROM LEGACY SYSTEM If you are migrating data… May 12, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer Storing Session State is the right key word. http://msdn.microsoft.com/en-us/library/ms972429.aspx http://www.devarticles.com/c/a/ASP/Maintaining-Session-State-With-ASP/… May 12, 2026 at 8:54 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.