Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralRe: Get all the network activity data in Resouce Monitor Pin
Richard MacCutchan19-Aug-15 20:51
mveRichard MacCutchan19-Aug-15 20:51 
AnswerRe: Get all the network activity data in Resouce Monitor Pin
Nitzan Levi19-Aug-15 9:57
Nitzan Levi19-Aug-15 9:57 
GeneralRe: Get all the network activity data in Resouce Monitor Pin
LeHuuTien19-Aug-15 16:05
LeHuuTien19-Aug-15 16:05 
Questionertan tike dayview calendar control Pin
Member 1189642718-Aug-15 20:01
Member 1189642718-Aug-15 20:01 
AnswerRe: ertan tike dayview calendar control Pin
Pete O'Hanlon18-Aug-15 21:27
mvePete O'Hanlon18-Aug-15 21:27 
AnswerRe: ertan tike dayview calendar control Pin
Nitzan Levi19-Aug-15 10:08
Nitzan Levi19-Aug-15 10:08 
GeneralRe: ertan tike dayview calendar control Pin
Member 1189642720-Aug-15 19:09
Member 1189642720-Aug-15 19:09 
QuestionNullReference Exception when trying to cancel Connection Pin
Member 1191874118-Aug-15 15:11
Member 1191874118-Aug-15 15:11 
Hi! I'm going mad on this and don't know how to solve it...

I have a class ExecQuery which executes a SQL Script:

SQL
public LoadScreen ldScreen = null;  //the LoadScreen class

    public ExecQuery(ldScreen ld)
    {
        ldScreen = ld;
    }

 public void ececute()
 {
 /***some code here for preparation like path, filename etc***/

    conn = new SqlConnection(conString);

    server = new Server(new ServerConnection(conn));

    server.ConnectionContext.ExecuteNonQuery(script); //script is my textfile
 }



Now while this executes I'm showing a loading screen with a cancel button. When I hit the button I call an event in my LoadScreen class:

C#
private void cancel_Click(object sender, EventArgs e)
    {
        ExecQuery exec = new ExecQuery(this);

        if (InvokeRequired)
        {
            BeginInvoke(new MethodInvoker(delegate() { exec.cancelProcess(); }));
        }

        else
        {
            exec.cancelProcess();
        }
    }



This takes me right back to my ExecQuery class and to the method:

C#
public void cancelProcess()
    {

       server.ConnectionContext.Cancel();
    }



where I get a NullReference Exception because server is null. I know why this happens. I shouldn't make that instance of the ExecQuery class at one point but I don't know how to solve this. I tried workarounds and nothing works.
How to get the server variable from the loading screen (which opens before the server variable gets a value)?
SuggestionRe: NullReference Exception when trying to cancel Connection Pin
Richard MacCutchan18-Aug-15 21:59
mveRichard MacCutchan18-Aug-15 21:59 
GeneralRe: NullReference Exception when trying to cancel Connection Pin
Member 1191874118-Aug-15 23:00
Member 1191874118-Aug-15 23:00 
GeneralRe: NullReference Exception when trying to cancel Connection Pin
Richard MacCutchan18-Aug-15 23:06
mveRichard MacCutchan18-Aug-15 23:06 
AnswerRe: NullReference Exception when trying to cancel Connection Pin
Eddy Vluggen18-Aug-15 23:47
professionalEddy Vluggen18-Aug-15 23:47 
Question"Attempted to read or write protected memory." Why? Pin
DPaul199418-Aug-15 9:36
DPaul199418-Aug-15 9:36 
GeneralRe: "Attempted to read or write protected memory." Why? Pin
harold aptroot18-Aug-15 11:42
harold aptroot18-Aug-15 11:42 
QuestionTask Parallel Programming Pin
ankitsoftdev18-Aug-15 7:36
ankitsoftdev18-Aug-15 7:36 
AnswerRe: Task Parallel Programming Pin
Dave Kreskowiak18-Aug-15 13:47
mveDave Kreskowiak18-Aug-15 13:47 
AnswerRe: Task Parallel Programming Pin
Pete O'Hanlon18-Aug-15 21:26
mvePete O'Hanlon18-Aug-15 21:26 
QuestionAynchronous approach on event Pin
dabuskol17-Aug-15 20:22
dabuskol17-Aug-15 20:22 
AnswerRe: Aynchronous approach on event Pin
Pete O'Hanlon17-Aug-15 23:04
mvePete O'Hanlon17-Aug-15 23:04 
AnswerRe: Aynchronous approach on event Pin
Afzaal Ahmad Zeeshan17-Aug-15 23:26
professionalAfzaal Ahmad Zeeshan17-Aug-15 23:26 
QuestionRe: Aynchronous approach on event Pin
Ravi Bhavnani18-Aug-15 4:55
professionalRavi Bhavnani18-Aug-15 4:55 
AnswerRe: Aynchronous approach on event Pin
dabuskol23-Aug-15 1:07
dabuskol23-Aug-15 1:07 
AnswerRe: Aynchronous approach on event Pin
dabuskol8-Sep-15 20:15
dabuskol8-Sep-15 20:15 
Questionmysql data reader Pin
abdujalilc17-Aug-15 20:13
abdujalilc17-Aug-15 20:13 
AnswerRe: mysql data reader Pin
OriginalGriff17-Aug-15 21:39
mveOriginalGriff17-Aug-15 21:39 

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.