Noob here in C#, so I'm having an issue trying to call a function in C# with system event args. I know the issue isn't with system event args, but what is the correct way I should call this type of function?
Error1: An object reference is required for the non-static field, method, or property 'ConsoleApplication3.Program.Reject_call(object, System.EventArgs)'
Error2: An object reference is required for the non-static field, method, or property 'ConsoleApplication3.Program.Accept_call(object, System.EventArgs)'
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Lync.Model;
using Microsoft.Lync.Model.Conversation;
using Microsoft.Lync.Model.Conversation.AudioVideo;
namespace ConsoleApplication3
{
class Program
{
//holds the Lync client instance
private static LyncClient _client;
//holds the reference to the conversation associated with this window
private Conversation conversation;
//self participant's AvModality
private AVModality avModality;
private static void Main(string[] args)
{
//Obtains the lync client instance
_client = LyncClient.GetClient();
consoleInputReadRoutine();
_client.ConversationManager.ConversationAdded += ConversationManager_ConversationAdded;
_client.ConversationManager.ConversationRemoved += ConversationManager_ConversationRemoved;
Console.ReadLine();
}
static void ConversationManager_ConversationAdded(object sender, ConversationManagerEventArgs e)
{
e.Conversation.Modalities[ModalityTypes.AudioVideo].ModalityStateChanged += Program_ModalityStateChanged;
}
static void Program_ModalityStateChanged(object sender, ModalityStateChangedEventArgs e)
{
Console.WriteLine("Modality state changed " + String.Format("{0} => {1}", e.OldState, e.NewState));
}
static void consoleInputReadRoutine()
{
bool done = false;
while(!done){
string input = Console.ReadLine(); // Get string from user
Console.WriteLine("user input {0}\n", input);
// Set exit condition.
if(String.Compare(input, "exit") == 0){
done = true;
}
else if (String.Compare(input, "reject") == 0)
{
//Do a reject call.
Reject_call(null, new EventArgs());
}
else if(String.Compare(input, "answer") == 0)
{
//Do a answer call.
Accept_call(null, new EventArgs());
}
}
}
// Accepts an incoming call: AvModality.Accept()
private void Accept_call(object sender, EventArgs e)
{
//accepts an incoming invite (syncronous operation)
avModality.Accept();
}
// Rejects an incoming call: AvModality.Reject()
private void Reject_call(object sender, EventArgs e)
{
//rejects an incoming invite (which will disconnect the call)
//the ModalityDisconnectReason may be used to specify a reason to the caller side
//the reason may be shown on the Lync client conversation window
avModality.Reject(ModalityDisconnectReason.Decline);
}
static void ConversationManager_ConversationRemoved(object sender, ConversationManagerEventArgs e)
{
//Exit out of program if you wish after conversation is removed.
}
}
}