質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Windows Forms

Windows Forms(WinForms)はMicrosoft .NET フレームワークに含まれる視覚的なアプリケーションのプログラミングインターフェイス(API)です。WinFormsは管理されているコードの既存のWindowsのAPIをラップすることで元のMicrosoft Windowsのインターフェイスのエレメントにアクセスすることができます。

Q&A

解決済

1回答

1506閲覧

C# [デリゲート 'Action' には引数 2 を指定できません]の対処法方法が知りたい

退会済みユーザー

退会済みユーザー

総合スコア0

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

Windows Forms

Windows Forms(WinForms)はMicrosoft .NET フレームワークに含まれる視覚的なアプリケーションのプログラミングインターフェイス(API)です。WinFormsは管理されているコードの既存のWindowsのAPIをラップすることで元のMicrosoft Windowsのインターフェイスのエレメントにアクセスすることができます。

0グッド

0クリップ

投稿2022/07/31 01:15

提示コードですが///コメント部内部のコードで以下のエラーが出るのですがこれはどうやって対処したらいいのでしょうか?
デリゲート 'Action' には引数 2 を指定できませんとありますが二つの引数を設定したい場合が知りたいです。

エラー CS1593 デリゲート 'Action' には引数 2 を指定できません

リファレンス: https://docs.microsoft.com/ja-jp/dotnet/api/system.threading.tasks.taskfactory.startnew?view=net-6.0#system-threading-tasks-taskfactory-startnew(system-action((system-object))-system-object-system-threading-cancellationtoken-system-threading-tasks-taskcreationoptions-system-threading-tasks-taskscheduler)

cs

1 2 private async void buttonConvert_Click(object sender, EventArgs e) 3 { 4 5 Action<SemaphoreSlim,FileData> action = (SemaphoreSlim slim,FileData data) => 6 { 7 8 //Process(slim, data.getFilePath(),data.getSavePath()); 9 10 this.Invoke((Action)(() => 11 { 12 progressBar_float += progressBarPerFile; 13 progressBar.Value = (int)progressBar_float; 14 })); 15 16 }; 17 18 if (folderBrowserDialogSavePath.SelectedPath != "") 19 { 20 if(filePathList.Count > 0) 21 { 22 progressBarPerFile = 100.0f / (float)filePathList.Count; //プログラスバーを設定 23 24 buttonConvert.Enabled = false; 25 Stopwatch sw = new Stopwatch(); 26 sw.Start(); 27 var slim = new SemaphoreSlim(5); 28 29 for(int j = 0; j < filePathList.Count; j++) 30 { 31 ///////////////////////////////////////////////////////////////// 32 taskList.Add(Task.Factory.StartNew((slim,data) => 33 { 34 35 //Process(slim, data.getFilePath(),data.getSavePath()); 36 37 this.Invoke((Action)(() => 38 { 39 progressBar_float += progressBarPerFile; 40 progressBar.Value = (int)progressBar_float; 41 })); 42 43 } )); 44 ////////////////////////////////////////////////////////////////// 45 } 46 47 48 49 50 51 52 await Task.WhenAll(taskList); 53 buttonConvert.Enabled = true; 54 55 progressBar.Value = 0; 56 sw.Stop(); 57 TimeSpan ts = sw.Elapsed; 58 59 Debug.WriteLine("convert time: " + ts.TotalSeconds +"."+ ts.Milliseconds); 60 } 61 else 62 { 63 MessageBox.Show("NO input file(s)", "", MessageBoxButtons.OK, MessageBoxIcon.Error); 64 } 65 } 66 else 67 { 68 MessageBox.Show("\n\n NO set save path", "", MessageBoxButtons.OK, MessageBoxIcon.Error); 69 } 70 71 } 72 73

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

StartNew(Action)に対して、Actionではなく、Action<SemaphoreSlim,FileData>を指定しているような気がします。
https://docs.microsoft.com/ja-jp/dotnet/api/system.threading.tasks.taskfactory.startnew?view=net-6.0#system-threading-tasks-taskfactory-startnew(system-action)

Action<SemaphoreSlim,FileData>を実行したいのであれば、
StartNew(()=>action(slim, data))などの形で実行すればよいかと思われます。

投稿2022/08/24 21:59

matari

総合スコア40

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問