Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
QuestionWPF problem with ScrollViewer Pin
Federico Barbieri20-Mar-14 6:50
Federico Barbieri20-Mar-14 6:50 
QuestionRe: WPF problem with ScrollViewer Pin
Kenneth Haugland20-Mar-14 20:43
mvaKenneth Haugland20-Mar-14 20:43 
SuggestionRe: WPF problem with ScrollViewer Pin
Richard MacCutchan20-Mar-14 22:40
mveRichard MacCutchan20-Mar-14 22:40 
GeneralRe: WPF problem with ScrollViewer Pin
Federico Barbieri20-Mar-14 23:47
Federico Barbieri20-Mar-14 23:47 
Question//solved// help making class available to all Pin
Bosskardo20-Mar-14 4:19
Bosskardo20-Mar-14 4:19 
AnswerRe: help making class available to all Pin
Pete O'Hanlon20-Mar-14 4:57
mvePete O'Hanlon20-Mar-14 4:57 
AnswerRe: help making class available to all Pin
OriginalGriff20-Mar-14 5:56
mveOriginalGriff20-Mar-14 5:56 
AnswerRe: help making class available to all Pin
BobJanova20-Mar-14 7:55
BobJanova20-Mar-14 7:55 
There is an implicit interface here: this code can never work in a form which doesn't have an OutputConsole and an ErrorConsole, as well as working with InvokeC (I don't know what that requires but presumably BeginInvoke).

So the most general you can get would be to make the thing passed to the constructor be an instance of that interface:

interface IMessageLogger {
 void LogToOutput(string message);
 void LogToError(string message);
 void InvokeAsync(Action<string> method, string method);
}

class WC { // this name is terrible, change it!
 private IMessageLogger logger;
 public WC(IMessageLogger logger) { this.logger = logger; }

 public void ConWrite(string text, int target = 0) {
  Console.WriteLine(text);
  switch(target) {
   case 1: logger.InvokeAsync(logger.LogToOutput, text); break;
   case 2: logger.InvokeAsync(logger.LogToError, text); break;
 }
}


There's a design decision here about whether that asynchroneity should be hidden inside the implementation of LogToOutput; I'd say it probably should, but I wanted to leave this code recognisably derived from yours.

Your MainWin would then need to implement IMessageLogger (writing items to the OutputConsole and ErrorConsole in the LogToOutput and LogToError methods). InvokeAsync would be a thin cover on BeginInvoke or Invoke:

public void InvokeAsync(Action<string> method, string text) {
 // IIRC you can't use a lambda here for some reason
 BeginInvoke(delegate() { method(text) }); 
}

GeneralRe: help making class available to all Pin
Bosskardo21-Mar-14 1:44
Bosskardo21-Mar-14 1:44 
QuestionMessage Removed Pin
20-Mar-14 3:39
protectorMarco Bertschi20-Mar-14 3:39 
Questionhow to use Response.Clear() in c# Pin
rincy sivan20-Mar-14 1:51
rincy sivan20-Mar-14 1:51 
AnswerRe: how to use Response.Clear() in c# Pin
Rob Philpott20-Mar-14 3:02
Rob Philpott20-Mar-14 3:02 
Questionc# code to copy paste whole pivot table in another sheet of excel Pin
rajnknit0719-Mar-14 23:32
rajnknit0719-Mar-14 23:32 
QuestionRe: c# code to copy paste whole pivot table in another sheet of excel Pin
Eddy Vluggen20-Mar-14 10:27
professionalEddy Vluggen20-Mar-14 10:27 
Question[solved] Passage of events between WinForms Pin
Mario 5619-Mar-14 23:27
Mario 5619-Mar-14 23:27 
QuestionRe: Passage of events between WinForms Pin
Eddy Vluggen20-Mar-14 6:37
professionalEddy Vluggen20-Mar-14 6:37 
AnswerRe: Passage of events between WinForms Pin
Mario 5620-Mar-14 7:33
Mario 5620-Mar-14 7:33 
GeneralRe: Passage of events between WinForms Pin
Eddy Vluggen20-Mar-14 10:35
professionalEddy Vluggen20-Mar-14 10:35 
GeneralRe: Passage of events between WinForms Pin
Mario 5620-Mar-14 14:44
Mario 5620-Mar-14 14:44 
GeneralRe: Passage of events between WinForms Pin
Eddy Vluggen21-Mar-14 7:29
professionalEddy Vluggen21-Mar-14 7:29 
AnswerRe: Passage of events between WinForms Pin
BobJanova20-Mar-14 8:06
BobJanova20-Mar-14 8:06 
GeneralRe: Passage of events between WinForms Pin
Mario 5620-Mar-14 9:51
Mario 5620-Mar-14 9:51 
GeneralRe: Passage of events between WinForms Pin
BobJanova21-Mar-14 0:20
BobJanova21-Mar-14 0:20 
GeneralRe: Passage of events between WinForms [Solved] Pin
Mario 5621-Mar-14 6:56
Mario 5621-Mar-14 6:56 
QuestionConvert HTML content to Rtf format or save it into Rtf file without the help of interop dll in c# Pin
Member 1068161419-Mar-14 19:09
Member 1068161419-Mar-14 19:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.