4 Replies - 921 Views - Last Post: 16 February 2012 - 12:51 PM Rate Topic: -----

#1 mayis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 12

No overload for '_initCompleted' matches delegate 'System.

Posted 16 February 2012 - 11:57 AM

Hi everyone I am newbie in C# and I still struggle with It, I converting from vb.net to c# and I get this error and I have not idea in vb.net is working but NOT in C#, THANKS IN ADVANCE

No overload for '_initCompleted' matches delegate 'System.AsyncCallbac

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Threading;
using System.Windows.Threading;
//Namespace iContract.UI
public partial class SplashWindow
{
    private static AsyncCallback InitCompleted;
    private static IAsyncResult result;
    
    private void SplashWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        InitCompleted = _initCompleted;      
        iContract.Application test = new iContract.Application();
        result = test.dLoadSplash.BeginInvoke(this, InitCompleted, null);
        //result = My.Application.dLoadSplash.BeginInvoke(Me, InitCompleted, Nothing)
    }

    private void _initCompleted()
    {
        iContract.Application test = new iContract.Application();
        test.dLoadSplash.EndInvoke(result);
        //My.Application.dLoadSplash.EndInvoke(result)
        Dispatcher.BeginInvoke(new Action(_closeWindow), System.Windows.Threading.DispatcherPriority.Normal, null);
    }

    private void _closeWindow()
    {
        Close();
    }

    public void SetProgress(double val)
    {
        Dispatcher.BeginInvoke(new Action<double>(_SetProgress), System.Windows.Threading.DispatcherPriority.Normal, val);
    }

    private void _SetProgress(double val)
    {
        prog.Value = val;
    }
}




this in vb.net when its working

Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Windows
Imports System.Threading
Imports System.Windows.Threading
'Namespace iContract.UI
Partial Public Class SplashWindow
    Private Shared InitCompleted As AsyncCallback
    Private Shared result As IAsyncResult
    Private Sub SplashWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        InitCompleted = AddressOf _initCompleted
        Dim test As New iContract.Application
        result = test.dLoadSplash.BeginInvoke(Me, InitCompleted, Nothing)
        'result = My.Application.dLoadSplash.BeginInvoke(Me, InitCompleted, Nothing)
    End Sub
    Private Sub _initCompleted()
        Dim test As New iContract.Application
        test.dLoadSplash.EndInvoke(result)
        'My.Application.dLoadSplash.EndInvoke(result)
        Dispatcher.BeginInvoke(New Action(AddressOf _closeWindow), Windows.Threading.DispatcherPriority.Normal, Nothing)
    End Sub

    Private Sub _closeWindow()
        Close()
    End Sub
    Public Sub SetProgress(ByVal val As Double)
        Dispatcher.BeginInvoke(New Action(Of Double)(AddressOf _SetProgress), Windows.Threading.DispatcherPriority.Normal, val)
    End Sub
    Private Sub _SetProgress(ByVal val As Double)
        prog.Value = val
    End Sub
End Class
'End Namespace




Is This A Good Question/Topic? 0
  • +

Replies To: No overload for '_initCompleted' matches delegate 'System.

#2 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: No overload for '_initCompleted' matches delegate 'System.

Posted 16 February 2012 - 12:09 PM

Since I'm not on my dev machine, I can't test this but:

Try to use the additive assignment operator (+=) with the delegate:

Use:
InitCompleted += _initCompleted;



Instead of:
InitCompleted = _initCompleted;



NOTE: You should really think of using alternative names for your methods. Methods should generally start with a capital letter, in other words should be named in PascalCase. The dash(_)name notation is mostly used for variables.

This post has been edited by RexGrammer: 16 February 2012 - 12:12 PM

Was This Post Helpful? 0
  • +
  • -

#3 mayis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 12

Re: No overload for '_initCompleted' matches delegate 'System.

Posted 16 February 2012 - 12:29 PM

Thanks RexGrammer for your Help.
I did it. but the error is still there plus one more

Operator '+=' cannot be applied to operands of type 'System.AsyncCallback' and 'method group'
No overload for '_initCompleted' matches delegate 'System.AsyncCallback'
Was This Post Helpful? 0
  • +
  • -

#4 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: No overload for '_initCompleted' matches delegate 'System.

Posted 16 February 2012 - 12:32 PM

The problem is that the AsyncCallback delegate demands a method that returns void, and has 1 parameter of type IAsyncResult.

Your _initCompleted method has no parameters, so you need to change it to this:

private void _initCompleted(IAsyncResult result)
{
        iContract.Application test = new iContract.Application();
        test.dLoadSplash.EndInvoke(result);
        //My.Application.dLoadSplash.EndInvoke(result)
        Dispatcher.BeginInvoke(new Action(_closeWindow), System.Windows.Threading.DispatcherPriority.Normal, null);
}


Was This Post Helpful? 1
  • +
  • -

#5 mayis  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 14-February 12

Re: No overload for '_initCompleted' matches delegate 'System.

Posted 16 February 2012 - 12:51 PM

Thanks So So Much RexGrammer this is working. I really feel inspired to learn more. Thanks a lot :flowers:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1