By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,686 Members | 1,510 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,686 IT Pros & Developers. It's quick & easy.

multi application

P: n/a
Hi, Ive written my application and published it. Leaving the editor
open, I install my newly made application and run it. Works perfect,
then I open it a second time so Ive got two instances of the same
application running. The second crashes bringing them both down, when
I choose stop debugging. Could take 2mins, sometimes 10mins. Is this
anything to do with how Im publishing, or could they be cross
referencing each other. I wondering if in code, Im supposed to tel to
2nd 3rd etc that this is a new instance.
Regards Robert
Dec 11 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thankyou for your reply. The application connects to betfairs api and
gets current odds on horses in a particular race. I dont think theres
shared resources on the pc. Ive looked at the limits to the api as im
using there free version. I do have a off the shelf application which
does a simular job, and I can open this multiple times with out
conflict, which makes me think its not the api, as it uses the same
api. It happens when one goes to collect the prices, and the object is
null. Im thinking now that it may be a threading problem.
regards Robert
Dec 11 '07 #2

P: n/a
Can I enter large chunks of code here. This is were it breaks down.
Before tis Im basically loading the form, adding a graph and user
control were the odds are shown. What Im going to try is to write a
second application using a different names just to see that its if its
me or the api.

#region
GetMarketPricesCompressedTask_OnGetGetMarketPrices Compressed(betfair.UK.exchange.GetMarketPricesResp
respUK, betfair.AU.exchange.GetMarketPricesCompressedResp respAU,
Tasks.BettingExchangeType m_exchange)
private void
GetMarketPricesCompressedTask_OnGetGetMarketPrices Compressed(betfair.UK.exchange.GetMarketPricesComp ressedResp
respUK, betfair.AU.exchange.GetMarketPricesCompressedResp respAU)
{
if (InvokeRequired)
{
Invoke(new
Tasks.GetMarketPricesCompressedTask.OnGetMarketPri cesCompressedDelegate(GetMarketPricesCompressedTas k_OnGetGetMarketPricesCompressed),
new object[] { respUK, respAU });
}
else
{
if (respUK != null)
{

string[] status;
string[] prices =
(respUK.marketPrices).Split('|'); // will return an array of 3 strings
etc.

if (prices[0].Contains("NR"))
{
status = prices[0].Split('~');

prices = (respUK.marketPrices).Split(':'); //
will return an array of 3 strings etc.

}
else
{
prices = (respUK.marketPrices).Split(':'); //
will return an array of 3 strings etc.

status = prices[0].Split('~');

}
double inplay = double.Parse(status[3]);
if (inplay == 0)
{

if (status[2] != "CLOSED")
{
//if (status[2] != "SUSPENDED")
//{
lblMarketStatus.Text = status[2];
lblLastRefresh.Text = status[8];

for (int i = 1; i <
(prices.GetUpperBound(0)) + 1; i++)
{
if ((prices[i].Contains("\\")) |
(prices[i].Contains(")")))
{
}
else
{

string[] data =
prices[i].Split('|');
string[] ids =
data[0].Split('~');
string comb = data[1] +
data[2];
string[] values =
comb.Split('~');
if (ids[0] ==
selectionId.ToString())
{
string rowName = ids[0];
MarketViewRow row =
(MarketViewRow)m_marketViewRows[rowName];

double backPrice1 = 0.0;
backAmountAvailable1 =
0.0;
if (values.Length 1)
{
if (values[0] != null)
{
backPrice1 =
double.Parse(values[0]);

backAmountAvailable1 = double.Parse(values[1]);
}
}

double backPrice2 = 0.0;
backAmountAvailable2 =
0.0;
if (values.Length 5)
{
if (values[4] != null)
{
backPrice2 =
double.Parse(values[4]);

backAmountAvailable2 = double.Parse(values[5]);
}
}

double backPrice3 = 0.0;
backAmountAvailable3 =
0.0;
if (values.Length 9)
{
if (values[8] != null)
{
backPrice3 =
double.Parse(values[8]);

backAmountAvailable3 = double.Parse(values[9]);
}
}

double layPrice1 = 0.0;
layAmountAvailable1 = 0.0;
if (values.Length 13)
{
if (values[12] !=
null)
{
layPrice1 =
double.Parse(values[12]);

layAmountAvailable1 = double.Parse(values[13]);
}
}

double layPrice2 = 0.0;
layAmountAvailable2 = 0.0;
if (values.Length 17)
{
if (values[16] !=
null)
{
layPrice2 =
double.Parse(values[16]);

layAmountAvailable2 = double.Parse(values[17]);
}
}

double layPrice3 = 0.0;
layAmountAvailable3 = 0.0;
if (values.Length 21)
{
if (values[20] !=
null)
{
layPrice3 =
double.Parse(values[20]);

layAmountAvailable3 = double.Parse(values[21]);
}
}

//
================================================== ================================================== =
//CALCS
row.DisplayPrices("uk",
backPrice1, backAmountAvailable1, backPrice2, backAmountAvailable2,
backPrice3, backAmountAvailable3, layPrice1, layAmountAvailable1,
layPrice2, layAmountAvailable2, layPrice3, layAmountAvailable3);

double allbacks =
(backAmountAvailable1 + backAmountAvailable2 + backAmountAvailable3);
double alllays =
(layAmountAvailable1 + layAmountAvailable2 + layAmountAvailable3);
double totalbacklay =
(allbacks + alllays);

percentCount =
(((allbacks) / (allbacks + alllays)) * 100);
laypercentCount =
(((alllays) / (allbacks + alllays)) * 100);

seventypercent.Add(tick,
70);
thirtypercent.Add(tick,
30);

backPercent.Add(tick,
percentCount);


if (backAmountAvailable1 <
layAmountAvailable1 && backAmountAvailable2 < layAmountAvailable2 &&
backAmountAvailable3 < layAmountAvailable3)
{

Allamountschange.Add(tick, 25);
}
else if
(backAmountAvailable1 layAmountAvailable1 && backAmountAvailable2 >
layAmountAvailable2 && backAmountAvailable3 layAmountAvailable3)
{

Allamountschange.Add(tick,75);
}
else
{

Allamountschange.Add(tick, 50);
}
if (tick < 16)
{
//total amount
available

//
backData.Add(allbacks);
//
layData.Add(alllays);
//
totalavailabletoback.Add(Convert.ToDouble(tick),
Convert.ToDouble(allbacks));
//
totalavailabletolay.Add(Convert.ToDouble(tick),
Convert.ToDouble(alllays));

//Odds

backPriceOdds.Add(backPrice1);//constant
Backodds.Add(Convert.ToDouble(tick), Convert.ToDouble(backPrice1));//
odds graph
//averages
//addAveback.Add(0);
// addAvelay.Add(0);
addAvebackOdds.Add(0);
;

//bols
//
upperbackcalcs.Add(0);
//
lowerbackcalcs.Add(0);
//
upperlaycalcs.Add(0);
//
lowerlaycalcs.Add(0);
upperbackOddscalcs.Add(0);

lowerbackOddscalcs.Add(0);
//
bvlbolschange.Add(tick, 0);
tick++;
}
else if (tick 15)
{

//total amount
available

//
backData.Add(allbacks);
//
layData.Add(alllays);

//Odds
backPriceOdds.Add(backPrice1);
//
backPercent.Add(tick, percentCount);

//total amount
available graph
//
totalavailabletoback.Add(Convert.ToDouble(tick),
Convert.ToDouble(allbacks));
//
totalavailabletolay.Add(Convert.ToDouble(tick),
Convert.ToDouble(alllays));
//Odds graph

Backodds.Add(Convert.ToDouble(tick), Convert.ToDouble(backPrice1));
//Backave.Clear();
//Layave.Clear();
BackaveOdds.Clear();
//get average & stddev
int w =
((backPriceOdds.Count) - 15);
for (int z =
((backPriceOdds.Count) - 15); z < ((backPriceOdds.Count)); z++)
{
//averages
//
Backave.Add(backData[z]);
//
Layave.Add(layData[z]);

BackaveOdds.Add(backPriceOdds[z]);

}

//ave calcs
// Avelay =
GetAvg(Layave);
// Aveback =
GetAvg(Backave);

AvebackOdds =
GetAvg(BackaveOdds);
//dev calcs
//stdbackDev =
GetStandardDeviation(Backave);
//stdLayDev =
GetStandardDeviation(Layave);
stdbackDevOdds =
GetStandardDeviation(BackaveOdds);
//ave constants
//
addAveback.Add(Aveback);
//
addAvelay.Add(Avelay);

addAvebackOdds.Add(AvebackOdds);
//bols constants
//
upperbackcalcs.Add(Aveback + (1.9 * stdbackDev));
//
lowerbackcalcs.Add(Aveback - (1.9 * stdbackDev));
//
upperlaycalcs.Add(Avelay + (1.9 * stdLayDev));
//
lowerlaycalcs.Add(Avelay - (1.9 * stdLayDev));
upperbackOddscalcs.Add(AvebackOdds + (1.9 * stdbackDevOdds));

lowerbackOddscalcs.Add(AvebackOdds - (1.9 * stdbackDevOdds));
//ave graph
//
amountbackAverage.Add(Convert.ToDouble(tick),
Convert.ToDouble(Aveback));
//
amountlayAverage.Add(Convert.ToDouble(tick),
Convert.ToDouble(Avelay));

amountbackAverageOdds.Add(Convert.ToDouble(tick),
Convert.ToDouble(AvebackOdds));

//bols graph
//
upperBack.Add(Convert.ToDouble(tick), Convert.ToDouble(Aveback + (1.9
* stdbackDev)));
//
lowerBack.Add(Convert.ToDouble(tick), Convert.ToDouble(Aveback - (1.9
* stdbackDev)));
//
upperlay.Add(Convert.ToDouble(tick), Convert.ToDouble(Avelay + (1.9 *
stdLayDev)));
//
lowerlay.Add(Convert.ToDouble(tick), Convert.ToDouble(Avelay - (1.9 *
stdLayDev)));

upperBackOdds.Add(Convert.ToDouble(tick), Convert.ToDouble(AvebackOdds
+ (1.9 * stdbackDevOdds)));

lowerBackOdds.Add(Convert.ToDouble(tick), Convert.ToDouble(AvebackOdds
- (1.9 * stdbackDevOdds)));
//bols bars
//amount
//backBols.Clear();
// layBols.Clear();
//backValue =
(allbacks - (Aveback - (1.9 * stdbackDev))) / ((Aveback + (1.9 *
stdbackDev)) - (Aveback - (1.9 * stdbackDev)));
// layValue = (alllays
- (Avelay - (1.9 * stdLayDev))) / ((Avelay + (1.9 * stdLayDev)) -
(Avelay - (1.9 * stdLayDev)));

// linediffs.Add(tick,
2.25);
//if (backValue < 0.2
&& layValue 0.9)
// {
//
bvlbolschange.Add(tick, 2.5);
// }
// else if (backValue >
0.9 && layValue < 0.2)
// {
//
bvlbolschange.Add(tick, 2);
// }
// else
// {
//
bvlbolschange.Add(tick, 2.25);
// }
//back odds bols dif


backoddsvalue =
(backPrice1 - (AvebackOdds - (1.9 * stdbackDevOdds))) / ((AvebackOdds
+ (1.9 * stdbackDevOdds)) - (AvebackOdds - (1.9 * stdbackDevOdds)));
if (backoddsvalue < 0)
{

oddsbolschange.Add(tick, 0);
}
else if (backoddsvalue
1)
{

oddsbolschange.Add(tick, -1);
}
else
{

oddsbolschange.Add(tick, 0);
}
//bandwidth
//bandBackamountwidth
= ((Aveback + (1.9 * stdbackDev)) - (Aveback - (1.9 * stdbackDev))) /
Aveback; ;
// bandLayamountwidth =
((Avelay + (1.9 * stdLayDev)) - (Avelay - (1.9 * stdLayDev))) /
Avelay;

//backBols.Add(1,
backValue);
//layBols.Add(1,
layValue);

tick++;
}
availCreateGraph(zedGraphControl1);

}
}

}

}
else
{
timer1.Stop();
lblLastRefresh.Text =
status[2].ToString();
lblMarketStatus.Text =
status[2].ToString();

}
}
else
{
timer1.Stop();
panelInPlay.Visible = true;
}

}
//'================================================= ================================================== =====================

else if (respAU != null)
{

string[] status;



string[] prices =
(respAU.marketPrices).Split('|'); // will return an array of 3 strings
etc.

if (prices[0].Contains("NR"))
{
status = prices[0].Split('~');

prices = (respAU.marketPrices).Split(':'); //
will return an array of 3 strings etc.
}
else
{
prices = (respAU.marketPrices).Split(':'); //
will return an array of 3 strings etc.

status = prices[0].Split('~');

}

double inplay = double.Parse(status[3]);
if (inplay == 0)
{

if (status[2] != "CLOSED")
{
if (status[2] != "SUSPENDED")
{
lblMarketStatus.Text = status[2];
lblLastRefresh.Text = status[8];

for (int i = 1; i <
(prices.GetUpperBound(0)) + 1; i++)
{
if ((prices[i].Contains("\\")) |
(prices[i].Contains(")")))
{
}
else
{
string[] data =
prices[i].Split('|');
string[] ids =
data[0].Split('~');
string comb = data[1] +
data[2];
string[] values =
comb.Split('~');
if (ids[0] ==
selectionId.ToString())
{

string rowName = ids[0];

MarketViewRow row =
(MarketViewRow)m_marketViewRows[rowName];

double backPrice1 = 0.0;
backAmountAvailable1 = 0.0;
if (values.Length 1)
{
if (values[0] != null)
{
backPrice1 =
double.Parse(values[0]);
backAmountAvailable1 =
double.Parse(values[1]);
}
}

double backPrice2 = 0.0;
backAmountAvailable2 = 0.0;
if (values.Length 5)
{
if (values[4] != null)
{
backPrice2 =
double.Parse(values[4]);
backAmountAvailable2 =
double.Parse(values[5]);
}
}

double backPrice3 = 0.0;
backAmountAvailable3 = 0.0;
if (values.Length 9)
{
if (values[8] != null)
{
backPrice3 =
double.Parse(values[8]);
backAmountAvailable3 =
double.Parse(values[9]);
}
}

double layPrice1 = 0.0;
layAmountAvailable1 = 0.0;
if (values.Length 13)
{
if (values[12] != null)
{
layPrice1 =
double.Parse(values[12]);
layAmountAvailable1 =
double.Parse(values[13]);
}
}

double layPrice2 = 0.0;
layAmountAvailable2 = 0.0;
if (values.Length 17)
{
if (values[16] != null)
{
layPrice2 =
double.Parse(values[16]);
layAmountAvailable2 =
double.Parse(values[17]);
}
}

double layPrice3 = 0.0;
layAmountAvailable3 = 0.0;
if (values.Length 21)
{
if (values[20] != null)
{
layPrice3 =
double.Parse(values[20]);
layAmountAvailable3 =
double.Parse(values[21]);
}
}
percentCount = 50;
laypercentCount = 50;

//
================================================== ================================================== =
//CALCS

row.DisplayPrices("au",
backPrice1, backAmountAvailable1, backPrice2, backAmountAvailable2,
backPrice3, backAmountAvailable3, layPrice1, layAmountAvailable1,
layPrice2, layAmountAvailable2, layPrice3, layAmountAvailable3);

double allbacks =
(backAmountAvailable1 + backAmountAvailable2 + backAmountAvailable3);
double alllays =
(layAmountAvailable1 + layAmountAvailable2 + layAmountAvailable3);
double totalbacklay =
(allbacks + alllays);

percentCount = (((allbacks) /
(allbacks + alllays)) * 100);
laypercentCount =
(((alllays) / (allbacks + alllays)) * 100);

seventypercent.Add(tick, 70);
thirtypercent.Add(tick, 30);


if (backAmountAvailable1 <
layAmountAvailable1 && backAmountAvailable2 < layAmountAvailable2 &&
backAmountAvailable3 < layAmountAvailable3)
{
Allamountschange.Add(tick,
25);
}
else if (backAmountAvailable1
layAmountAvailable1 && backAmountAvailable2 layAmountAvailable2 &&
backAmountAvailable3 layAmountAvailable3)
{
Allamountschange.Add(tick,
75);
}
else
{
Allamountschange.Add(tick,
50);
}
if (tick < 16)
{
//total amount available

backData.Add(allbacks);
layData.Add(alllays);
//Odds

backPriceOdds.Add(backPrice1);
Backodds.Add(Convert.ToDouble(tick), Convert.ToDouble(backPrice1));
backPercent.Add(tick,
percentCount);

//averages
addAveback.Add(0);
addAvelay.Add(0);
addAvebackOdds.Add(0);
;

//bols
upperbackcalcs.Add(0);
lowerbackcalcs.Add(0);
upperlaycalcs.Add(0);
lowerlaycalcs.Add(0);

upperbackOddscalcs.Add(0);
lowerbackOddscalcs.Add(0);
bvlbolschange.Add(tick,
0);
tick++;
}
else if (tick 15)
{

//total amount available

backData.Add(allbacks);
layData.Add(alllays);

//Odds
backPriceOdds.Add(backPrice1);
backPercent.Add(tick,
percentCount);
//Odds graph

Backodds.Add(Convert.ToDouble(tick), Convert.ToDouble(backPrice1));
Backave.Clear();
Layave.Clear();
BackaveOdds.Clear();
//get average & stddev
int w =
((backPriceOdds.Count) - 15);
for (int z =
((backPriceOdds.Count) - 15); z < ((backPriceOdds.Count)); z++)
{
//averages

Backave.Add(backData[z]);

Layave.Add(layData[z]);

BackaveOdds.Add(backPriceOdds[z]);

}

//ave calcs
Avelay = GetAvg(Layave);
Aveback = GetAvg(Backave);

AvebackOdds =
GetAvg(BackaveOdds);
//dev calcs
stdbackDev =
GetStandardDeviation(Backave);
stdLayDev =
GetStandardDeviation(Layave);
stdbackDevOdds =
GetStandardDeviation(BackaveOdds);
//ave constants
addAveback.Add(Aveback);
addAvelay.Add(Avelay);

addAvebackOdds.Add(AvebackOdds);
//bols constants
upperbackcalcs.Add(Aveback
+ (1.9 * stdbackDev));
lowerbackcalcs.Add(Aveback
- (1.9 * stdbackDev));
upperlaycalcs.Add(Avelay +
(1.9 * stdLayDev));
lowerlaycalcs.Add(Avelay -
(1.9 * stdLayDev));
upperbackOddscalcs.Add(AvebackOdds + (1.9 * stdbackDevOdds));

lowerbackOddscalcs.Add(AvebackOdds - (1.9 * stdbackDevOdds));
//ave graph

amountbackAverage.Add(Convert.ToDouble(tick),
Convert.ToDouble(Aveback));

amountlayAverage.Add(Convert.ToDouble(tick),
Convert.ToDouble(Avelay));

amountbackAverageOdds.Add(Convert.ToDouble(tick),
Convert.ToDouble(AvebackOdds));

//bols graph

upperBack.Add(Convert.ToDouble(tick), Convert.ToDouble(Aveback + (1.9
* stdbackDev)));

lowerBack.Add(Convert.ToDouble(tick), Convert.ToDouble(Aveback - (1.9
* stdbackDev)));

upperlay.Add(Convert.ToDouble(tick), Convert.ToDouble(Avelay + (1.9 *
stdLayDev)));

lowerlay.Add(Convert.ToDouble(tick), Convert.ToDouble(Avelay - (1.9 *
stdLayDev)));

upperBackOdds.Add(Convert.ToDouble(tick), Convert.ToDouble(AvebackOdds
+ (1.9 * stdbackDevOdds)));

lowerBackOdds.Add(Convert.ToDouble(tick), Convert.ToDouble(AvebackOdds
- (1.9 * stdbackDevOdds)));
//bols bars
//amount
backBols.Clear();
layBols.Clear();
backValue = (allbacks -
(Aveback - (1.9 * stdbackDev))) / ((Aveback + (1.9 * stdbackDev)) -
(Aveback - (1.9 * stdbackDev)));
layValue = (alllays -
(Avelay - (1.9 * stdLayDev))) / ((Avelay + (1.9 * stdLayDev)) -
(Avelay - (1.9 * stdLayDev)));

linediffs.Add(tick, 2.25);
if (backValue < 0.2 &&
layValue 0.9)
{

bvlbolschange.Add(tick, 2.5);
}
else if (backValue 0.9
&& layValue < 0.2)
{

bvlbolschange.Add(tick, 2);
}
else
{

bvlbolschange.Add(tick, 2.25);
}
//back odds bols dif


backoddsvalue =
(backPrice1 - (AvebackOdds - (1.9 * stdbackDevOdds))) / ((AvebackOdds
+ (1.9 * stdbackDevOdds)) - (AvebackOdds - (1.9 * stdbackDevOdds)));
if (backoddsvalue < 0)
{

oddsbolschange.Add(tick, 0);
}
else if (backoddsvalue >
1)
{

oddsbolschange.Add(tick, -1);
}
else
{

oddsbolschange.Add(tick, 0);
}
//bandwidth
bandBackamountwidth =
((Aveback + (1.9 * stdbackDev)) - (Aveback - (1.9 * stdbackDev))) /
Aveback; ;
bandLayamountwidth =
((Avelay + (1.9 * stdLayDev)) - (Avelay - (1.9 * stdLayDev))) /
Avelay;

backBols.Add(1,
backValue);
layBols.Add(1, layValue);


tick++;
}
availCreateGraph(zedGraphControl1);


}
}
}
}
else
{
timer1.Stop();
lblLastRefresh.Text =
status[2].ToString();
lblMarketStatus.Text =
status[2].ToString();

}

}
else
{
timer1.Stop();
lblLastRefresh.Text =
status[2].ToString();
lblMarketStatus.Text =
status[2].ToString();

}
}
else
{
timer1.Stop();
lblLastRefresh.Text = "IN PLAY";
lblMarketStatus.Text = "IN PLAY";

}
}
}//FIRST ELSE
}//INV

#endregion

regards robert
Dec 11 '07 #3

P: n/a
Ok, I will eliminate the api first then atack the code. In the meen
time thanks for your time.
Regards Robert
Dec 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.