Click here to Skip to main content
15,881,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: split string into line C# Pin
PIEBALDconsult21-Aug-14 5:32
mvePIEBALDconsult21-Aug-14 5:32 
QuestionWindows Form KeyDown Pin
Zeyad Jalil21-Aug-14 0:06
professionalZeyad Jalil21-Aug-14 0:06 
AnswerRe: Windows Form KeyDown Pin
Eddy Vluggen21-Aug-14 0:34
professionalEddy Vluggen21-Aug-14 0:34 
AnswerRe: Windows Form KeyDown Pin
joost.versteegen21-Aug-14 2:58
joost.versteegen21-Aug-14 2:58 
GeneralRe: Windows Form KeyDown Pin
Rob Philpott21-Aug-14 6:25
Rob Philpott21-Aug-14 6:25 
QuestionMobile Money Transfer Application Pin
Soren Neilsen20-Aug-14 22:42
Soren Neilsen20-Aug-14 22:42 
AnswerRe: Mobile Money Transfer Application Pin
OriginalGriff20-Aug-14 22:44
mveOriginalGriff20-Aug-14 22:44 
QuestionOpenFileDialog works from app but not from a spawned thread after use InvokeMember to load assembly / class Pin
JudyL_MD20-Aug-14 10:41
JudyL_MD20-Aug-14 10:41 
I've stripped my problem down to the bare minimum. I've got a form that, in response to user action, needs to display the OpenFileDialog dialog. When this form is started "normally" i.e. using Application.Run, the dialog appears. When this form is started via reflection it fails. Fails in this case means that the code successfully runs all the way to the actual OpenFileDialog.ShowDialog call -- ShowDialog is stepped into but the dialog never appears and the call never returns.

Here's the code:
The direct app:

C#
using UiLibrary;
namespace DirectApp
{
  static class Program
  {
    [STAThread]
    static void Main ()
    {
      Application.EnableVisualStyles ();
      Application.SetCompatibleTextRenderingDefault (false);
      Application.Run (new Form1 ());
} } }

The indirect app:
C#
namespace IndirectApp
{
  public partial class DummyFormToLaunchTheRealUI
  {
    public DummyFormToLaunchTheRealUI () { InitializeComponent (); }

    private void button1_Click (object sender, EventArgs e)
    {
      Assembly abs = Assembly.LoadFile (@"C:\temp\tester\UiLibrary\bin\debug\UiLibrary.dll");
      Type startType = abs.GetType ("UiLibrary.Startup", true);
      object startLib = startType.InvokeMember ("", BindingFlags.CreateInstance, null, null, new object[0]);
      startType.InvokeMember ("Run", BindingFlags.InvokeMethod, null, startLib, new object[0]);
} } }

The library:
namespace UiLibrary
{
  public class Startup
  {
    public void Run ()
    {
      Thread runThread = new Thread (new ThreadStart (ActualWork));
      runThread.Start ();
    }

    private void ActualWork ()
    {
      Form1 f = new Form1 ();
      f.ShowDialog ();
    }
  }

  public partial class Form1 : Form
  {
    public Form1 () { InitializeComponent (); }

    private void button1_click (object sender, EventArgs e)
    {
      OpenFileDialog ofd = new OpenFileDialog ();
      // this field always correct
      ofd.InitialDirectory = Environment.ExpandEnvironmentVariables (@"%USERPROFILE%\Downloads");
      // doesn't change if call ShowDialog with no paramters
      ofd.ShowDialog (this);
} } }

I've got to show Form1 from the library in its own thread since I want IndirectApp to remain responsive to UI. This is stripped down - in my real code Form1 is much more complex, successfully launching its own forms and doing other stuff regardless of which method is use to fire it up.

Visual Studio 2012 using .NET 3.5 on Windows 7 SP1

Any ideas on what's particular to the OpenFileDialog class? This is the only one of the common dialogs that is used.
Thanks all!
Judy
Be wary of strong drink. It can make you shoot at tax collectors - and miss.
Lazarus Long, "Time Enough For Love" by Robert A. Heinlein

AnswerRe: OpenFileDialog works from app but not from a spawned thread after use InvokeMember to load assembly / class PinPopular
Richard Deeming20-Aug-14 10:59
mveRichard Deeming20-Aug-14 10:59 
GeneralRe: OpenFileDialog works from app but not from a spawned thread after use InvokeMember to load assembly / class Pin
JudyL_MD20-Aug-14 11:04
JudyL_MD20-Aug-14 11:04 
GeneralRe: OpenFileDialog works from app but not from a spawned thread after use InvokeMember to load assembly / class Pin
Ravi Bhavnani20-Aug-14 11:12
professionalRavi Bhavnani20-Aug-14 11:12 
QuestionSolution for Oracle.DataAccess.Client.OracleException Pin
Member 1099617820-Aug-14 2:25
Member 1099617820-Aug-14 2:25 
AnswerRe: Solution for Oracle.DataAccess.Client.OracleException Pin
Richard MacCutchan20-Aug-14 3:09
mveRichard MacCutchan20-Aug-14 3:09 
AnswerRe: Solution for Oracle.DataAccess.Client.OracleException Pin
Dave Kreskowiak20-Aug-14 4:09
mveDave Kreskowiak20-Aug-14 4:09 
Questioncode in c# Pin
Member 1087469320-Aug-14 2:02
Member 1087469320-Aug-14 2:02 
AnswerRe: code in c# Pin
OriginalGriff20-Aug-14 2:21
mveOriginalGriff20-Aug-14 2:21 
AnswerRe: code in c# Pin
Lambin22-Aug-14 1:33
Lambin22-Aug-14 1:33 
QuestionEquivalent Linq Query for SQL Query? Pin
murali_utr19-Aug-14 16:55
murali_utr19-Aug-14 16:55 
AnswerRe: Equivalent Linq Query for SQL Query? Pin
Richard MacCutchan19-Aug-14 21:41
mveRichard MacCutchan19-Aug-14 21:41 
AnswerRe: Equivalent Linq Query for SQL Query? Pin
Sibeesh KV29-Sep-14 19:43
professionalSibeesh KV29-Sep-14 19:43 
QuestionMessage Closed Pin
19-Aug-14 12:19
omprakash jaiswal19-Aug-14 12:19 
AnswerRe: mask attack Pin
Bernhard Hiller19-Aug-14 21:15
Bernhard Hiller19-Aug-14 21:15 
AnswerRe: mask attack PinPopular
OriginalGriff19-Aug-14 21:47
mveOriginalGriff19-Aug-14 21:47 
GeneralRe: mask attack Pin
Rob Philpott19-Aug-14 23:12
Rob Philpott19-Aug-14 23:12 
GeneralRe: mask attack Pin
OriginalGriff19-Aug-14 23:23
mveOriginalGriff19-Aug-14 23:23 

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.